gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

gen_resolver_utils.go (8107B)


      1 // Code generated by astool. DO NOT EDIT.
      2 
      3 package streams
      4 
      5 import (
      6 	"context"
      7 	"errors"
      8 	vocab "github.com/superseriousbusiness/activity/streams/vocab"
      9 )
     10 
     11 // ErrNoCallbackMatch indicates a Resolver could not match the ActivityStreams value to a callback function.
     12 var ErrNoCallbackMatch error = errors.New("activity stream did not match the callback function")
     13 
     14 // ErrUnhandledType indicates that an ActivityStreams value has a type that is not handled by the code that has been generated.
     15 var ErrUnhandledType error = errors.New("activity stream did not match any known types")
     16 
     17 // ErrPredicateUnmatched indicates that a predicate is accepting a type or interface that does not match an ActivityStreams value's type or interface.
     18 var ErrPredicateUnmatched error = errors.New("activity stream did not match type demanded by predicate")
     19 
     20 // errCannotTypeAssertType indicates that the 'type' property returned by the ActivityStreams value cannot be type-asserted to its interface form.
     21 var errCannotTypeAssertType error = errors.New("activity stream type cannot be asserted to its interface")
     22 
     23 // ActivityStreamsInterface represents any ActivityStream value code-generated by
     24 // go-fed or compatible with the generated interfaces.
     25 type ActivityStreamsInterface interface {
     26 	// GetTypeName returns the ActiivtyStreams value's type.
     27 	GetTypeName() string
     28 	// VocabularyURI returns the vocabulary's URI as a string.
     29 	VocabularyURI() string
     30 }
     31 
     32 // Resolver represents any TypeResolver.
     33 type Resolver interface {
     34 	// Resolve will attempt to resolve an untyped ActivityStreams value into a
     35 	// Go concrete type.
     36 	Resolve(ctx context.Context, o ActivityStreamsInterface) error
     37 }
     38 
     39 // IsUnmatchedErr is true when the error indicates that a Resolver was
     40 // unsuccessful due to the ActivityStreams value not matching its callbacks or
     41 // predicates.
     42 func IsUnmatchedErr(err error) bool {
     43 	return err == ErrPredicateUnmatched || err == ErrUnhandledType || err == ErrNoCallbackMatch
     44 }
     45 
     46 // ToType attempts to resolve the generic JSON map into a Type.
     47 func ToType(c context.Context, m map[string]interface{}) (t vocab.Type, err error) {
     48 	var r *JSONResolver
     49 	r, err = NewJSONResolver(func(ctx context.Context, i vocab.ActivityStreamsAccept) error {
     50 		t = i
     51 		return nil
     52 	}, func(ctx context.Context, i vocab.ActivityStreamsActivity) error {
     53 		t = i
     54 		return nil
     55 	}, func(ctx context.Context, i vocab.ActivityStreamsAdd) error {
     56 		t = i
     57 		return nil
     58 	}, func(ctx context.Context, i vocab.ActivityStreamsAnnounce) error {
     59 		t = i
     60 		return nil
     61 	}, func(ctx context.Context, i vocab.ActivityStreamsApplication) error {
     62 		t = i
     63 		return nil
     64 	}, func(ctx context.Context, i vocab.ActivityStreamsArrive) error {
     65 		t = i
     66 		return nil
     67 	}, func(ctx context.Context, i vocab.ActivityStreamsArticle) error {
     68 		t = i
     69 		return nil
     70 	}, func(ctx context.Context, i vocab.ActivityStreamsAudio) error {
     71 		t = i
     72 		return nil
     73 	}, func(ctx context.Context, i vocab.ActivityStreamsBlock) error {
     74 		t = i
     75 		return nil
     76 	}, func(ctx context.Context, i vocab.ForgeFedBranch) error {
     77 		t = i
     78 		return nil
     79 	}, func(ctx context.Context, i vocab.ActivityStreamsCollection) error {
     80 		t = i
     81 		return nil
     82 	}, func(ctx context.Context, i vocab.ActivityStreamsCollectionPage) error {
     83 		t = i
     84 		return nil
     85 	}, func(ctx context.Context, i vocab.ForgeFedCommit) error {
     86 		t = i
     87 		return nil
     88 	}, func(ctx context.Context, i vocab.ActivityStreamsCreate) error {
     89 		t = i
     90 		return nil
     91 	}, func(ctx context.Context, i vocab.ActivityStreamsDelete) error {
     92 		t = i
     93 		return nil
     94 	}, func(ctx context.Context, i vocab.ActivityStreamsDislike) error {
     95 		t = i
     96 		return nil
     97 	}, func(ctx context.Context, i vocab.ActivityStreamsDocument) error {
     98 		t = i
     99 		return nil
    100 	}, func(ctx context.Context, i vocab.TootEmoji) error {
    101 		t = i
    102 		return nil
    103 	}, func(ctx context.Context, i vocab.ActivityStreamsEndpoints) error {
    104 		t = i
    105 		return nil
    106 	}, func(ctx context.Context, i vocab.ActivityStreamsEvent) error {
    107 		t = i
    108 		return nil
    109 	}, func(ctx context.Context, i vocab.ActivityStreamsFlag) error {
    110 		t = i
    111 		return nil
    112 	}, func(ctx context.Context, i vocab.ActivityStreamsFollow) error {
    113 		t = i
    114 		return nil
    115 	}, func(ctx context.Context, i vocab.ActivityStreamsGroup) error {
    116 		t = i
    117 		return nil
    118 	}, func(ctx context.Context, i vocab.TootIdentityProof) error {
    119 		t = i
    120 		return nil
    121 	}, func(ctx context.Context, i vocab.ActivityStreamsIgnore) error {
    122 		t = i
    123 		return nil
    124 	}, func(ctx context.Context, i vocab.ActivityStreamsImage) error {
    125 		t = i
    126 		return nil
    127 	}, func(ctx context.Context, i vocab.ActivityStreamsIntransitiveActivity) error {
    128 		t = i
    129 		return nil
    130 	}, func(ctx context.Context, i vocab.ActivityStreamsInvite) error {
    131 		t = i
    132 		return nil
    133 	}, func(ctx context.Context, i vocab.ActivityStreamsJoin) error {
    134 		t = i
    135 		return nil
    136 	}, func(ctx context.Context, i vocab.ActivityStreamsLeave) error {
    137 		t = i
    138 		return nil
    139 	}, func(ctx context.Context, i vocab.ActivityStreamsLike) error {
    140 		t = i
    141 		return nil
    142 	}, func(ctx context.Context, i vocab.ActivityStreamsLink) error {
    143 		t = i
    144 		return nil
    145 	}, func(ctx context.Context, i vocab.ActivityStreamsListen) error {
    146 		t = i
    147 		return nil
    148 	}, func(ctx context.Context, i vocab.ActivityStreamsMention) error {
    149 		t = i
    150 		return nil
    151 	}, func(ctx context.Context, i vocab.ActivityStreamsMove) error {
    152 		t = i
    153 		return nil
    154 	}, func(ctx context.Context, i vocab.ActivityStreamsNote) error {
    155 		t = i
    156 		return nil
    157 	}, func(ctx context.Context, i vocab.ActivityStreamsObject) error {
    158 		t = i
    159 		return nil
    160 	}, func(ctx context.Context, i vocab.ActivityStreamsOffer) error {
    161 		t = i
    162 		return nil
    163 	}, func(ctx context.Context, i vocab.ActivityStreamsOrderedCollection) error {
    164 		t = i
    165 		return nil
    166 	}, func(ctx context.Context, i vocab.ActivityStreamsOrderedCollectionPage) error {
    167 		t = i
    168 		return nil
    169 	}, func(ctx context.Context, i vocab.ActivityStreamsOrganization) error {
    170 		t = i
    171 		return nil
    172 	}, func(ctx context.Context, i vocab.ActivityStreamsPage) error {
    173 		t = i
    174 		return nil
    175 	}, func(ctx context.Context, i vocab.ActivityStreamsPerson) error {
    176 		t = i
    177 		return nil
    178 	}, func(ctx context.Context, i vocab.ActivityStreamsPlace) error {
    179 		t = i
    180 		return nil
    181 	}, func(ctx context.Context, i vocab.ActivityStreamsProfile) error {
    182 		t = i
    183 		return nil
    184 	}, func(ctx context.Context, i vocab.SchemaPropertyValue) error {
    185 		t = i
    186 		return nil
    187 	}, func(ctx context.Context, i vocab.W3IDSecurityV1PublicKey) error {
    188 		t = i
    189 		return nil
    190 	}, func(ctx context.Context, i vocab.ForgeFedPush) error {
    191 		t = i
    192 		return nil
    193 	}, func(ctx context.Context, i vocab.ActivityStreamsQuestion) error {
    194 		t = i
    195 		return nil
    196 	}, func(ctx context.Context, i vocab.ActivityStreamsRead) error {
    197 		t = i
    198 		return nil
    199 	}, func(ctx context.Context, i vocab.ActivityStreamsReject) error {
    200 		t = i
    201 		return nil
    202 	}, func(ctx context.Context, i vocab.ActivityStreamsRelationship) error {
    203 		t = i
    204 		return nil
    205 	}, func(ctx context.Context, i vocab.ActivityStreamsRemove) error {
    206 		t = i
    207 		return nil
    208 	}, func(ctx context.Context, i vocab.ForgeFedRepository) error {
    209 		t = i
    210 		return nil
    211 	}, func(ctx context.Context, i vocab.ActivityStreamsService) error {
    212 		t = i
    213 		return nil
    214 	}, func(ctx context.Context, i vocab.ActivityStreamsTentativeAccept) error {
    215 		t = i
    216 		return nil
    217 	}, func(ctx context.Context, i vocab.ActivityStreamsTentativeReject) error {
    218 		t = i
    219 		return nil
    220 	}, func(ctx context.Context, i vocab.ForgeFedTicket) error {
    221 		t = i
    222 		return nil
    223 	}, func(ctx context.Context, i vocab.ForgeFedTicketDependency) error {
    224 		t = i
    225 		return nil
    226 	}, func(ctx context.Context, i vocab.ActivityStreamsTombstone) error {
    227 		t = i
    228 		return nil
    229 	}, func(ctx context.Context, i vocab.ActivityStreamsTravel) error {
    230 		t = i
    231 		return nil
    232 	}, func(ctx context.Context, i vocab.ActivityStreamsUndo) error {
    233 		t = i
    234 		return nil
    235 	}, func(ctx context.Context, i vocab.ActivityStreamsUpdate) error {
    236 		t = i
    237 		return nil
    238 	}, func(ctx context.Context, i vocab.ActivityStreamsVideo) error {
    239 		t = i
    240 		return nil
    241 	}, func(ctx context.Context, i vocab.ActivityStreamsView) error {
    242 		t = i
    243 		return nil
    244 	})
    245 	if err != nil {
    246 		return
    247 	}
    248 	err = r.Resolve(c, m)
    249 	return
    250 }