lexicon devex tutorial
1// Code generated by indigo lexgen tool. DO NOT EDIT MANUALLY.
2
3// Lexicon schema: place.atwork.endorsement
4
5package placeatwork
6
7import (
8 "encoding/json"
9 "fmt"
10
11 comatproto "github.com/bluesky-social/indigo/api/atproto"
12 lexutil "github.com/bluesky-social/indigo/lex/util"
13)
14
15// A cryptographically-verified professional endorsement between two identities.
16type Endorsement struct {
17 LexiconTypeID string `json:"$type" cborgen:"$type,const=place.atwork.endorsement"`
18 // createdAt: Timestamp when the endorsement was created.
19 CreatedAt string `json:"createdAt" cborgen:"createdAt"`
20 // giver: The DID of the identity giving the endorsement.
21 Giver string `json:"giver" cborgen:"giver"`
22 // receiver: The DID of the identity receiving the endorsement.
23 Receiver string `json:"receiver" cborgen:"receiver"`
24 // signatures: Verified signatures from endorsement proofs (strong references).
25 Signatures []Endorsement_Signatures_Elem `json:"signatures,omitempty" cborgen:"signatures,omitempty"`
26 // text: The endorsement text content.
27 Text string `json:"text" cborgen:"text"`
28}
29
30type Endorsement_Signatures_Elem struct {
31 RepoStrongRef *comatproto.RepoStrongRef
32}
33
34func (t *Endorsement_Signatures_Elem) MarshalJSON() ([]byte, error) {
35 if t.RepoStrongRef != nil {
36 t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef"
37 return json.Marshal(t.RepoStrongRef)
38 }
39 return nil, fmt.Errorf("can not marshal empty union as JSON")
40}
41
42func (t *Endorsement_Signatures_Elem) UnmarshalJSON(b []byte) error {
43 typ, err := lexutil.TypeExtract(b)
44 if err != nil {
45 return err
46 }
47
48 switch typ {
49 case "com.atproto.repo.strongRef":
50 t.RepoStrongRef = new(comatproto.RepoStrongRef)
51 return json.Unmarshal(b, t.RepoStrongRef)
52 default:
53 return nil
54 }
55}