Remove interface based Resolver types.

They do not work as intended, due to differing signature for the
LessThan generated methods.
This commit is contained in:
Cory Slep 2019-02-06 20:39:10 +01:00
parent 9fc75b87b8
commit 4ca4b8235f
5 changed files with 24 additions and 1229 deletions

View File

@ -1096,7 +1096,7 @@ func (c *Converter) propertyPackageFiles(pg *gen.PropertyGenerator, vocabName st
// resolverFiles creates the files necessary for the resolvers.
func (c *Converter) resolverFiles(pkg gen.Package, manGen *gen.ManagerGenerator, root vocabulary) (files []*File, e error) {
rg := gen.NewResolverGenerator(root.allTypeArray(), manGen, pkg)
jsonRes, typeRes, intRes, typePredRes, intPredRes, errDefs, isUnFn, iFaces := rg.Definition()
jsonRes, typeRes, typePredRes, errDefs, isUnFn, iFaces := rg.Definition()
// Utils
file := jen.NewFilePath(pkg.Path())
for _, errDef := range errDefs {
@ -1127,14 +1127,6 @@ func (c *Converter) resolverFiles(pkg gen.Package, manGen *gen.ManagerGenerator,
FileName: "gen_type_resolver.go",
Directory: pkg.WriteDir(),
})
// Interface, not predicated
file = jen.NewFilePath(pkg.Path())
file.Add(intRes.Definition())
files = append(files, &File{
F: file,
FileName: "gen_interface_resolver.go",
Directory: pkg.WriteDir(),
})
// Type, Predicated
file = jen.NewFilePath(pkg.Path())
file.Add(typePredRes.Definition())
@ -1143,14 +1135,6 @@ func (c *Converter) resolverFiles(pkg gen.Package, manGen *gen.ManagerGenerator,
FileName: "gen_type_predicated_resolver.go",
Directory: pkg.WriteDir(),
})
// Interface, Predicated
file = jen.NewFilePath(pkg.Path())
file.Add(intPredRes.Definition())
files = append(files, &File{
F: file,
FileName: "gen_interface_predicated_resolver.go",
Directory: pkg.WriteDir(),
})
return
}

View File

@ -8,27 +8,25 @@ import (
)
const (
contextJSONLDName = "@context"
typePropertyName = "type"
jsonResolverStructName = "JSONResolver"
typeResolverStructName = "TypeResolver"
interfaceResolverStructName = "InterfaceResolver"
typePredicatedResolverStructName = "TypePredicatedResolver"
interfacePredicatedResolverStructName = "InterfacePredicatedResolver"
resolveMethod = "Resolve"
applyMethod = "Apply"
activityStreamInterface = "ActivityStreamsInterface"
resolverInterface = "Resolver"
callbackMember = "callbacks"
predicateMember = "predicate"
delegateMember = "delegate"
errorNoMatch = "ErrNoCallbackMatch"
errorUnhandled = "ErrUnhandledType"
errorPredicateUnmatched = "ErrPredicateUnmatched"
errorCannotTypeAssert = "errCannotTypeAssertType"
errorCannotTypeAssertPredicate = "errCannotTypeAssertPredicate"
isUnFnName = "IsUnmatchedErr"
toAliasMapFnName = "toAliasMap"
contextJSONLDName = "@context"
typePropertyName = "type"
jsonResolverStructName = "JSONResolver"
typeResolverStructName = "TypeResolver"
typePredicatedResolverStructName = "TypePredicatedResolver"
resolveMethod = "Resolve"
applyMethod = "Apply"
activityStreamInterface = "ActivityStreamsInterface"
resolverInterface = "Resolver"
callbackMember = "callbacks"
predicateMember = "predicate"
delegateMember = "delegate"
errorNoMatch = "ErrNoCallbackMatch"
errorUnhandled = "ErrUnhandledType"
errorPredicateUnmatched = "ErrPredicateUnmatched"
errorCannotTypeAssert = "errCannotTypeAssertType"
errorCannotTypeAssertPredicate = "errCannotTypeAssertPredicate"
isUnFnName = "IsUnmatchedErr"
toAliasMapFnName = "toAliasMap"
)
// ResolverGenerator generates the code required for the TypeResolver and the
@ -40,9 +38,7 @@ type ResolverGenerator struct {
cacheOnce sync.Once
cachedJSON *codegen.Struct
cachedTypePredicate *codegen.Struct
cachedInterfacePredicate *codegen.Struct
cachedType *codegen.Struct
cachedInterface *codegen.Struct
cachedErrNoMatch jen.Code
cachedErrUnhandled jen.Code
cachedErrPredicateUnmatched jen.Code
@ -71,7 +67,7 @@ func NewResolverGenerator(
// Definition returns the TypeResolver and PredicateTypeResolver.
//
// This function signature is pure garbage and yet I keep heaping it on.
func (r *ResolverGenerator) Definition() (jsonRes, typeRes, interfaceRes, typePredRes, interfacePredRes *codegen.Struct, errs []jen.Code, isUnFn *codegen.Function, iFaces []*codegen.Interface) {
func (r *ResolverGenerator) Definition() (jsonRes, typeRes, typePredRes *codegen.Struct, errs []jen.Code, isUnFn *codegen.Function, iFaces []*codegen.Interface) {
r.cacheOnce.Do(func() {
r.cachedJSON = codegen.NewStruct(
fmt.Sprintf("%s resolves a JSON-deserialized map into "+
@ -115,28 +111,6 @@ func (r *ResolverGenerator) Definition() (jsonRes, typeRes, interfaceRes, typePr
"error is returned if a callback function "+
"does not match this signature."),
r.resolverMembers())
r.cachedInterface = codegen.NewStruct(
fmt.Sprintf("%s resolves ActivityStreams values based "+
"on the interface or interfaces they satisfy.", interfaceResolverStructName),
interfaceResolverStructName,
r.interfaceResolverMethods(),
r.resolverFunctions(interfaceResolverStructName,
"creates a new Resolver that examines the "+
"interface assertions on an ActivityStreams "+
"value to determine "+
"what callback function to pass a concretely "+
"typed value. The callback may receive a "+
"value whose underlying ActivityStreams type "+
"does not match the concrete interface name "+
"in its signature. "+
"The callback functions must be "+
"of the form:\n\n"+
" func(context.Context, <TypeInterface>) error\n\n"+
"where TypeInterface is the code-generated "+
"interface for an ActivityStream type. An "+
"error is returned if a callback function "+
"does not match this signature."),
r.resolverMembers())
r.cachedTypePredicate = codegen.NewStruct(
fmt.Sprintf("%s resolves ActivityStreams values if "+
"the value satisfies a predicate condition "+
@ -160,33 +134,6 @@ func (r *ResolverGenerator) Definition() (jsonRes, typeRes, interfaceRes, typePr
"error is returned if the predicate does "+
"not match this signature."),
r.predicateResolverMembers())
r.cachedInterfacePredicate = codegen.NewStruct(
fmt.Sprintf("%s resolves ActivityStreams values if "+
"the value satisfies a predicate condition "+
"based on the interface or interfaces they "+
"satisfy.", interfacePredicatedResolverStructName),
interfacePredicatedResolverStructName,
r.interfacePredicatedResolverMethods(),
r.predicateResolverFunctions(interfacePredicatedResolverStructName,
"creates a new Resolver that applies a "+
"predicate to an ActivityStreams value to "+
"determine whether to Resolve or not. The "+
"ActivityStreams value's interface assertions "+
"are examined "+
"to determine if the predicate can apply "+
"itself to the value. The predicate will "+
"will receive a concrete value "+
"whose underlying ActivityStreams type "+
"may not match the concrete interface name, "+
"and could be completely unrelated "+
"ActivityStreams types."+
"The predicate function must be of the form: \n\n"+
" func(context.Context, <TypeInterface>) (bool, error)\n\n"+
"where TypeInterface is the code-generated "+
"interface for an ActivityStreams type. An "+
"error is returned if the predicate does "+
"not match this signature."),
r.predicateResolverMembers())
r.cachedErrNoMatch = r.errorNoMatch()
r.cachedErrUnhandled = r.errorUnhandled()
r.cachedErrPredicateUnmatched = r.errorPredicateUnmatched()
@ -196,7 +143,7 @@ func (r *ResolverGenerator) Definition() (jsonRes, typeRes, interfaceRes, typePr
r.cachedASInterface = r.asInterface()
r.cachedResolverInterface = r.resolverInterface()
})
return r.cachedJSON, r.cachedType, r.cachedInterface, r.cachedTypePredicate, r.cachedInterfacePredicate, []jen.Code{
return r.cachedJSON, r.cachedType, r.cachedTypePredicate, []jen.Code{
r.cachedErrNoMatch,
r.cachedErrUnhandled,
r.cachedErrPredicateUnmatched,
@ -519,68 +466,6 @@ func (r *ResolverGenerator) typeResolverMethods() (m []*codegen.Method) {
return
}
// interfaceResolverMethods returns the methods for the TypeResolver.
func (r *ResolverGenerator) interfaceResolverMethods() (m []*codegen.Method) {
impl := jen.Empty()
for _, t := range r.types {
impl = impl.If(
jen.List(
jen.Id("v"),
jen.Id("ok"),
).Op(":=").Id("o").Assert(
jen.Qual(t.PublicPackage().Path(), t.InterfaceName()),
),
jen.Id("ok"),
).Block(
jen.If(
jen.List(
jen.Id("fn"),
jen.Id("ok"),
).Op(":=").Id("i").Assert(
jen.Func().Parens(
jen.List(
jen.Qual("context", "Context"),
jen.Qual(t.PublicPackage().Path(), t.InterfaceName()),
),
).Error(),
),
jen.Id("ok"),
).Block(
jen.Return(
jen.Id("fn").Call(jen.Id("ctx"), jen.Id("v")),
),
),
jen.Commentf("Else: this callback function doesn't support this duck-typed interface."),
).Line()
}
m = append(m, codegen.NewCommentedValueMethod(
r.pkg.Path(),
resolveMethod,
interfaceResolverStructName,
[]jen.Code{
jen.Id("ctx").Qual("context", "Context"),
jen.Id("o").Id(activityStreamInterface),
},
[]jen.Code{
jen.Error(),
},
[]jen.Code{
jen.For(
jen.List(
jen.Id("_"),
jen.Id("i"),
).Op(":=").Range().Id(codegen.This()).Dot(callbackMember),
).Block(
impl,
),
jen.Return(
jen.Id(errorNoMatch),
),
},
fmt.Sprintf("%s applies the first callback function whose signature accepts an interface interpretation of the ActivityStreams value. Note that the Go interface rules mean that this can result in multiple unrelated ActivityStreams types to be passed into a single callback function and potentially causing unintended behaviors. It is best to assume nothing about the ActivityStreams' type in the callback function, and instead only reason about an ActivityStreams' properties. Returns an error if the ActivityStreams interface does not match callbackers or the value passed in is not go-fed compatible.", resolveMethod)))
return
}
// typePredicatedResolverMethods returns the methods for the TypePredicatedResolver.
func (r *ResolverGenerator) typePredicatedResolverMethods() (m []*codegen.Method) {
impl := jen.Empty()
@ -687,97 +572,6 @@ func (r *ResolverGenerator) typePredicatedResolverMethods() (m []*codegen.Method
return
}
// interfacePredicatedResolverMethods returns the methods for the PredicateTypeResolver.
func (r *ResolverGenerator) interfacePredicatedResolverMethods() (m []*codegen.Method) {
impl := jen.Empty()
for _, t := range r.types {
impl = impl.Case(
jen.Func().Parens(
jen.List(
jen.Qual("context", "Context"),
jen.Qual(t.PublicPackage().Path(), t.InterfaceName()),
),
).Parens(
jen.List(
jen.Bool(),
jen.Error(),
),
),
).Block(
jen.If(
jen.List(
jen.Id("v"),
jen.Id("ok"),
).Op(":=").Id("o").Assert(
jen.Qual(t.PublicPackage().Path(), t.InterfaceName()),
),
jen.Id("ok"),
).Block(
jen.List(
jen.Id("predicatePasses"),
jen.Err(),
).Op("=").Id("fn").Call(jen.Id("ctx"), jen.Id("v")),
).Else().Block(
jen.Return(
jen.False(),
jen.Id(errorPredicateUnmatched),
),
),
).Line()
}
m = append(m, codegen.NewCommentedValueMethod(
r.pkg.Path(),
applyMethod,
interfacePredicatedResolverStructName,
[]jen.Code{
jen.Id("ctx").Qual("context", "Context"),
jen.Id("o").Id(activityStreamInterface),
},
[]jen.Code{
jen.Bool(),
jen.Error(),
},
[]jen.Code{
jen.Var().Id("predicatePasses").Bool(),
jen.Var().Err().Error(),
jen.Switch(jen.Id("fn").Op(":=").Id(codegen.This()).Dot(predicateMember).Assert(jen.Type())).Block(
impl.Default().Block(
jen.Commentf("The constructor should guard against this error. If it is encountered, then there is a bug in the code generator."),
jen.Return(
jen.False(),
jen.Id(errorCannotTypeAssertPredicate),
),
),
),
jen.If(
jen.Err().Op("!=").Nil(),
).Block(
jen.Return(
jen.Id("predicatePasses"),
jen.Err(),
),
),
jen.If(
jen.Id("predicatePasses"),
).Block(
jen.Return(
jen.True(),
jen.Id(codegen.This()).Dot(delegateMember).Dot(resolveMethod).Call(
jen.Id("ctx"),
jen.Id("o"),
),
),
).Else().Block(
jen.Return(
jen.False(),
jen.Nil(),
),
),
},
fmt.Sprintf("%s uses a predicate to determine whether to resolve the ActivityStreams value. The predicate function is applied if its signature accepts an interface interpretation of the ActivityStreams value. Note that the Go interface rules mean that this can result in multiple unrelated ActivityStreams types to be passed into the predicate and potentially cause unintended behaviors. It is best to assume nothing about the ActivityStreams' type in the predicate function, and instead only reason about an ActivityStreams' properties. Returns an error if the ActivityStreams interface does not match the predicate or the resolver returns an error.", applyMethod)))
return
}
// resolverFunctions returns the functions for the TypeResolver.
func (r *ResolverGenerator) resolverFunctions(name, comment string) (f []*codegen.Function) {
f = append(f, codegen.NewCommentedFunction(
@ -954,7 +748,7 @@ func (r *ResolverGenerator) resolverInterface() *codegen.Interface {
Comment: fmt.Sprintf("%s will attempt to resolve an untyped ActivityStreams value into a Go concrete type.", resolveMethod),
},
},
fmt.Sprintf("%s represents any %s or %s.", resolverInterface, typeResolverStructName, interfaceResolverStructName))
fmt.Sprintf("%s represents any %s.", resolverInterface, typeResolverStructName))
}
// toAliasFunction returns the toAliasMap function

View File

@ -1,500 +0,0 @@
package streams
import (
"context"
"errors"
vocab "github.com/go-fed/activity/streams/vocab"
)
// InterfacePredicatedResolver resolves ActivityStreams values if the value
// satisfies a predicate condition based on the interface or interfaces they
// satisfy.
type InterfacePredicatedResolver struct {
delegate Resolver
predicate interface{}
}
// NewInterfacePredicatedResolver creates a new Resolver that applies a predicate
// to an ActivityStreams value to determine whether to Resolve or not. The
// ActivityStreams value's interface assertions are examined to determine if
// the predicate can apply itself to the value. The predicate will will
// receive a concrete value whose underlying ActivityStreams type may not
// match the concrete interface name, and could be completely unrelated
// ActivityStreams types.The predicate function must be of the form:
//
// func(context.Context, <TypeInterface>) (bool, error)
//
// where TypeInterface is the code-generated interface for an ActivityStreams
// type. An error is returned if the predicate does not match this signature.
func NewInterfacePredicatedResolver(delegate Resolver, predicate interface{}) (*InterfacePredicatedResolver, error) {
// The predicate must satisfy one known predicate function signature, or else we will generate a runtime error instead of silently fail.
switch predicate.(type) {
case func(context.Context, vocab.AcceptInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ActivityInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.AddInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.AnnounceInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ApplicationInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ArriveInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ArticleInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.AudioInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.BlockInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.CollectionInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.CollectionPageInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.CreateInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.DeleteInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.DislikeInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.DocumentInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.EventInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.FlagInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.FollowInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.GroupInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.IgnoreInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ImageInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.IntransitiveActivityInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.InviteInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.JoinInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.LeaveInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.LikeInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.LinkInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ListenInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.MentionInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.MoveInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.NoteInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ObjectInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.OfferInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.OrderedCollectionInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.OrderedCollectionPageInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.OrganizationInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.PageInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.PersonInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.PlaceInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ProfileInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.QuestionInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ReadInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.RejectInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.RelationshipInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.RemoveInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ServiceInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.TentativeAcceptInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.TentativeRejectInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.TombstoneInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.TravelInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.UndoInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.UpdateInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.VideoInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
case func(context.Context, vocab.ViewInterface) (bool, error):
// Do nothing, this predicate has a correct signature.
default:
return nil, errors.New("the predicate function is of the wrong signature and would never be called")
}
return &InterfacePredicatedResolver{
delegate: delegate,
predicate: predicate,
}, nil
}
// Apply uses a predicate to determine whether to resolve the ActivityStreams
// value. The predicate function is applied if its signature accepts an
// interface interpretation of the ActivityStreams value. Note that the Go
// interface rules mean that this can result in multiple unrelated
// ActivityStreams types to be passed into the predicate and potentially cause
// unintended behaviors. It is best to assume nothing about the
// ActivityStreams' type in the predicate function, and instead only reason
// about an ActivityStreams' properties. Returns an error if the
// ActivityStreams interface does not match the predicate or the resolver
// returns an error.
func (this InterfacePredicatedResolver) Apply(ctx context.Context, o ActivityStreamsInterface) (bool, error) {
var predicatePasses bool
var err error
switch fn := this.predicate.(type) {
case func(context.Context, vocab.AcceptInterface) (bool, error):
if v, ok := o.(vocab.AcceptInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ActivityInterface) (bool, error):
if v, ok := o.(vocab.ActivityInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.AddInterface) (bool, error):
if v, ok := o.(vocab.AddInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.AnnounceInterface) (bool, error):
if v, ok := o.(vocab.AnnounceInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ApplicationInterface) (bool, error):
if v, ok := o.(vocab.ApplicationInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ArriveInterface) (bool, error):
if v, ok := o.(vocab.ArriveInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ArticleInterface) (bool, error):
if v, ok := o.(vocab.ArticleInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.AudioInterface) (bool, error):
if v, ok := o.(vocab.AudioInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.BlockInterface) (bool, error):
if v, ok := o.(vocab.BlockInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.CollectionInterface) (bool, error):
if v, ok := o.(vocab.CollectionInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.CollectionPageInterface) (bool, error):
if v, ok := o.(vocab.CollectionPageInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.CreateInterface) (bool, error):
if v, ok := o.(vocab.CreateInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.DeleteInterface) (bool, error):
if v, ok := o.(vocab.DeleteInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.DislikeInterface) (bool, error):
if v, ok := o.(vocab.DislikeInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.DocumentInterface) (bool, error):
if v, ok := o.(vocab.DocumentInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.EventInterface) (bool, error):
if v, ok := o.(vocab.EventInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.FlagInterface) (bool, error):
if v, ok := o.(vocab.FlagInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.FollowInterface) (bool, error):
if v, ok := o.(vocab.FollowInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.GroupInterface) (bool, error):
if v, ok := o.(vocab.GroupInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.IgnoreInterface) (bool, error):
if v, ok := o.(vocab.IgnoreInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ImageInterface) (bool, error):
if v, ok := o.(vocab.ImageInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.IntransitiveActivityInterface) (bool, error):
if v, ok := o.(vocab.IntransitiveActivityInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.InviteInterface) (bool, error):
if v, ok := o.(vocab.InviteInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.JoinInterface) (bool, error):
if v, ok := o.(vocab.JoinInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.LeaveInterface) (bool, error):
if v, ok := o.(vocab.LeaveInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.LikeInterface) (bool, error):
if v, ok := o.(vocab.LikeInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.LinkInterface) (bool, error):
if v, ok := o.(vocab.LinkInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ListenInterface) (bool, error):
if v, ok := o.(vocab.ListenInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.MentionInterface) (bool, error):
if v, ok := o.(vocab.MentionInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.MoveInterface) (bool, error):
if v, ok := o.(vocab.MoveInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.NoteInterface) (bool, error):
if v, ok := o.(vocab.NoteInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ObjectInterface) (bool, error):
if v, ok := o.(vocab.ObjectInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.OfferInterface) (bool, error):
if v, ok := o.(vocab.OfferInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.OrderedCollectionInterface) (bool, error):
if v, ok := o.(vocab.OrderedCollectionInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.OrderedCollectionPageInterface) (bool, error):
if v, ok := o.(vocab.OrderedCollectionPageInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.OrganizationInterface) (bool, error):
if v, ok := o.(vocab.OrganizationInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.PageInterface) (bool, error):
if v, ok := o.(vocab.PageInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.PersonInterface) (bool, error):
if v, ok := o.(vocab.PersonInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.PlaceInterface) (bool, error):
if v, ok := o.(vocab.PlaceInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ProfileInterface) (bool, error):
if v, ok := o.(vocab.ProfileInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.QuestionInterface) (bool, error):
if v, ok := o.(vocab.QuestionInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ReadInterface) (bool, error):
if v, ok := o.(vocab.ReadInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.RejectInterface) (bool, error):
if v, ok := o.(vocab.RejectInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.RelationshipInterface) (bool, error):
if v, ok := o.(vocab.RelationshipInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.RemoveInterface) (bool, error):
if v, ok := o.(vocab.RemoveInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ServiceInterface) (bool, error):
if v, ok := o.(vocab.ServiceInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.TentativeAcceptInterface) (bool, error):
if v, ok := o.(vocab.TentativeAcceptInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.TentativeRejectInterface) (bool, error):
if v, ok := o.(vocab.TentativeRejectInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.TombstoneInterface) (bool, error):
if v, ok := o.(vocab.TombstoneInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.TravelInterface) (bool, error):
if v, ok := o.(vocab.TravelInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.UndoInterface) (bool, error):
if v, ok := o.(vocab.UndoInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.UpdateInterface) (bool, error):
if v, ok := o.(vocab.UpdateInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.VideoInterface) (bool, error):
if v, ok := o.(vocab.VideoInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
case func(context.Context, vocab.ViewInterface) (bool, error):
if v, ok := o.(vocab.ViewInterface); ok {
predicatePasses, err = fn(ctx, v)
} else {
return false, ErrPredicateUnmatched
}
default:
// The constructor should guard against this error. If it is encountered, then there is a bug in the code generator.
return false, errCannotTypeAssertPredicate
}
if err != nil {
return predicatePasses, err
}
if predicatePasses {
return true, this.delegate.Resolve(ctx, o)
} else {
return false, nil
}
}

View File

@ -1,483 +0,0 @@
package streams
import (
"context"
"errors"
vocab "github.com/go-fed/activity/streams/vocab"
)
// InterfaceResolver resolves ActivityStreams values based on the interface or
// interfaces they satisfy.
type InterfaceResolver struct {
callbacks []interface{}
}
// NewInterfaceResolver creates a new Resolver that examines the interface
// assertions on an ActivityStreams value to determine what callback function
// to pass a concretely typed value. The callback may receive a value whose
// underlying ActivityStreams type does not match the concrete interface name
// in its signature. The callback functions must be of the form:
//
// func(context.Context, <TypeInterface>) error
//
// where TypeInterface is the code-generated interface for an ActivityStream
// type. An error is returned if a callback function does not match this
// signature.
func NewInterfaceResolver(callbacks ...interface{}) (*InterfaceResolver, error) {
for _, cb := range callbacks {
// Each callback function must satisfy one known function signature, or else we will generate a runtime error instead of silently fail.
switch cb.(type) {
case func(context.Context, vocab.AcceptInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ActivityInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.AddInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.AnnounceInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ApplicationInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ArriveInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ArticleInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.AudioInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.BlockInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.CollectionInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.CollectionPageInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.CreateInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.DeleteInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.DislikeInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.DocumentInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.EventInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.FlagInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.FollowInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.GroupInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.IgnoreInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ImageInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.IntransitiveActivityInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.InviteInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.JoinInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.LeaveInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.LikeInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.LinkInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ListenInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.MentionInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.MoveInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.NoteInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ObjectInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.OfferInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.OrderedCollectionInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.OrderedCollectionPageInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.OrganizationInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.PageInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.PersonInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.PlaceInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ProfileInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.QuestionInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ReadInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.RejectInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.RelationshipInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.RemoveInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ServiceInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.TentativeAcceptInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.TentativeRejectInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.TombstoneInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.TravelInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.UndoInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.UpdateInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.VideoInterface) error:
// Do nothing, this callback has a correct signature.
case func(context.Context, vocab.ViewInterface) error:
// Do nothing, this callback has a correct signature.
default:
return nil, errors.New("a callback function is of the wrong signature and would never be called")
}
}
return &InterfaceResolver{callbacks: callbacks}, nil
}
// Resolve applies the first callback function whose signature accepts an
// interface interpretation of the ActivityStreams value. Note that the Go
// interface rules mean that this can result in multiple unrelated
// ActivityStreams types to be passed into a single callback function and
// potentially causing unintended behaviors. It is best to assume nothing
// about the ActivityStreams' type in the callback function, and instead only
// reason about an ActivityStreams' properties. Returns an error if the
// ActivityStreams interface does not match callbackers or the value passed in
// is not go-fed compatible.
func (this InterfaceResolver) Resolve(ctx context.Context, o ActivityStreamsInterface) error {
for _, i := range this.callbacks {
if v, ok := o.(vocab.AcceptInterface); ok {
if fn, ok := i.(func(context.Context, vocab.AcceptInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ActivityInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ActivityInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.AddInterface); ok {
if fn, ok := i.(func(context.Context, vocab.AddInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.AnnounceInterface); ok {
if fn, ok := i.(func(context.Context, vocab.AnnounceInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ApplicationInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ApplicationInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ArriveInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ArriveInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ArticleInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ArticleInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.AudioInterface); ok {
if fn, ok := i.(func(context.Context, vocab.AudioInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.BlockInterface); ok {
if fn, ok := i.(func(context.Context, vocab.BlockInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.CollectionInterface); ok {
if fn, ok := i.(func(context.Context, vocab.CollectionInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.CollectionPageInterface); ok {
if fn, ok := i.(func(context.Context, vocab.CollectionPageInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.CreateInterface); ok {
if fn, ok := i.(func(context.Context, vocab.CreateInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.DeleteInterface); ok {
if fn, ok := i.(func(context.Context, vocab.DeleteInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.DislikeInterface); ok {
if fn, ok := i.(func(context.Context, vocab.DislikeInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.DocumentInterface); ok {
if fn, ok := i.(func(context.Context, vocab.DocumentInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.EventInterface); ok {
if fn, ok := i.(func(context.Context, vocab.EventInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.FlagInterface); ok {
if fn, ok := i.(func(context.Context, vocab.FlagInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.FollowInterface); ok {
if fn, ok := i.(func(context.Context, vocab.FollowInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.GroupInterface); ok {
if fn, ok := i.(func(context.Context, vocab.GroupInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.IgnoreInterface); ok {
if fn, ok := i.(func(context.Context, vocab.IgnoreInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ImageInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ImageInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.IntransitiveActivityInterface); ok {
if fn, ok := i.(func(context.Context, vocab.IntransitiveActivityInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.InviteInterface); ok {
if fn, ok := i.(func(context.Context, vocab.InviteInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.JoinInterface); ok {
if fn, ok := i.(func(context.Context, vocab.JoinInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.LeaveInterface); ok {
if fn, ok := i.(func(context.Context, vocab.LeaveInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.LikeInterface); ok {
if fn, ok := i.(func(context.Context, vocab.LikeInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.LinkInterface); ok {
if fn, ok := i.(func(context.Context, vocab.LinkInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ListenInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ListenInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.MentionInterface); ok {
if fn, ok := i.(func(context.Context, vocab.MentionInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.MoveInterface); ok {
if fn, ok := i.(func(context.Context, vocab.MoveInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.NoteInterface); ok {
if fn, ok := i.(func(context.Context, vocab.NoteInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ObjectInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ObjectInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.OfferInterface); ok {
if fn, ok := i.(func(context.Context, vocab.OfferInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.OrderedCollectionInterface); ok {
if fn, ok := i.(func(context.Context, vocab.OrderedCollectionInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.OrderedCollectionPageInterface); ok {
if fn, ok := i.(func(context.Context, vocab.OrderedCollectionPageInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.OrganizationInterface); ok {
if fn, ok := i.(func(context.Context, vocab.OrganizationInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.PageInterface); ok {
if fn, ok := i.(func(context.Context, vocab.PageInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.PersonInterface); ok {
if fn, ok := i.(func(context.Context, vocab.PersonInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.PlaceInterface); ok {
if fn, ok := i.(func(context.Context, vocab.PlaceInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ProfileInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ProfileInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.QuestionInterface); ok {
if fn, ok := i.(func(context.Context, vocab.QuestionInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ReadInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ReadInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.RejectInterface); ok {
if fn, ok := i.(func(context.Context, vocab.RejectInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.RelationshipInterface); ok {
if fn, ok := i.(func(context.Context, vocab.RelationshipInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.RemoveInterface); ok {
if fn, ok := i.(func(context.Context, vocab.RemoveInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ServiceInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ServiceInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.TentativeAcceptInterface); ok {
if fn, ok := i.(func(context.Context, vocab.TentativeAcceptInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.TentativeRejectInterface); ok {
if fn, ok := i.(func(context.Context, vocab.TentativeRejectInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.TombstoneInterface); ok {
if fn, ok := i.(func(context.Context, vocab.TombstoneInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.TravelInterface); ok {
if fn, ok := i.(func(context.Context, vocab.TravelInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.UndoInterface); ok {
if fn, ok := i.(func(context.Context, vocab.UndoInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.UpdateInterface); ok {
if fn, ok := i.(func(context.Context, vocab.UpdateInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.VideoInterface); ok {
if fn, ok := i.(func(context.Context, vocab.VideoInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
if v, ok := o.(vocab.ViewInterface); ok {
if fn, ok := i.(func(context.Context, vocab.ViewInterface) error); ok {
return fn(ctx, v)
}
// Else: this callback function doesn't support this duck-typed interface.
}
}
return ErrNoCallbackMatch
}

View File

@ -27,7 +27,7 @@ type ActivityStreamsInterface interface {
GetName() string
}
// Resolver represents any TypeResolver or InterfaceResolver.
// Resolver represents any TypeResolver.
type Resolver interface {
// Resolve will attempt to resolve an untyped ActivityStreams value into a
// Go concrete type.