lexicon devex tutorial
at main 2.2 kB view raw
1// Code generated by indigo lexgen tool. DO NOT EDIT MANUALLY. 2 3// Lexicon schema: place.atwork.listing 4 5package placeatwork 6 7import ( 8 "encoding/json" 9 "fmt" 10 11 appbsky "github.com/bluesky-social/indigo/api/bsky" 12 lexutil "github.com/bluesky-social/indigo/lex/util" 13 "tangled.org/bnewbold.net/atwork-cli/communitylexicon" 14) 15 16// A job listing 17type Listing struct { 18 LexiconTypeID string `json:"$type" cborgen:"$type,const=place.atwork.listing"` 19 // applyLink: URL where applicants can apply for the job. 20 ApplyLink *string `json:"applyLink,omitempty" cborgen:"applyLink,omitempty"` 21 // banner: Larger horizontal image to display behind job listing view. 22 Banner *lexutil.LexBlob `json:"banner,omitempty" cborgen:"banner,omitempty"` 23 // description: The description of the job listing. 24 Description string `json:"description" cborgen:"description"` 25 // facets: Annotations of text (mentions, URLs, hashtags, etc). 26 Facets []appbsky.RichtextFacet `json:"facets,omitempty" cborgen:"facets,omitempty"` 27 // locations: Locations that are relevant to the job listing. 28 Locations []Listing_Locations_Elem `json:"locations,omitempty" cborgen:"locations,omitempty"` 29 // notAfter: Client-declared timestamp when the job listing expires. 30 NotAfter string `json:"notAfter" cborgen:"notAfter"` 31 // notBefore: Client-declared timestamp when the job listing becomes visible. 32 NotBefore string `json:"notBefore" cborgen:"notBefore"` 33 // title: The title of the job listing. 34 Title string `json:"title" cborgen:"title"` 35} 36 37type Listing_Locations_Elem struct { 38 LocationHthree *communitylexicon.LocationHthree 39} 40 41func (t *Listing_Locations_Elem) MarshalJSON() ([]byte, error) { 42 if t.LocationHthree != nil { 43 t.LocationHthree.LexiconTypeID = "community.lexicon.location.hthree" 44 return json.Marshal(t.LocationHthree) 45 } 46 return nil, fmt.Errorf("can not marshal empty union as JSON") 47} 48 49func (t *Listing_Locations_Elem) UnmarshalJSON(b []byte) error { 50 typ, err := lexutil.TypeExtract(b) 51 if err != nil { 52 return err 53 } 54 55 switch typ { 56 case "community.lexicon.location.hthree": 57 t.LocationHthree = new(communitylexicon.LocationHthree) 58 return json.Unmarshal(b, t.LocationHthree) 59 default: 60 return nil 61 } 62}