Documentation ¶
Overview ¶
Package lex generates Go code for lexicons.
(It is not a lexer.)
Index ¶
- Constants
- func BuildExtDefMap(ss []*Schema, packages []Package) map[string]*ExtDef
- func CreateHandlerStub(pkg string, impmap map[string]string, dir string, schemas []*Schema, ...) error
- func FixRecordReferences(schemas []*Schema, defmap map[string]*ExtDef, prefix string)
- func GenCodeForSchema(pkg Package, reqcode bool, s *Schema, packages []Package, ...) error
- func Run(schemas []*Schema, packages []Package) error
- func WriteServerHandlers(w io.Writer, schemas []*Schema, pkg string, impmap map[string]string) error
- func WriteXrpcServer(w io.Writer, schemas []*Schema, pkg string, impmap map[string]string) error
- type ExtDef
- type InputType
- type OutputType
- type Package
- type Schema
- type TypeSchema
- func (s *TypeSchema) TypeName() string
- func (s *TypeSchema) WriteHandlerStub(w io.Writer, fname, shortname, impname string) error
- func (s *TypeSchema) WriteRPC(w io.Writer, typename, inputname string) error
- func (s *TypeSchema) WriteRPCHandler(w io.Writer, fname, shortname, impname string) error
- func (ts *TypeSchema) WriteType(name string, w io.Writer) error
Constants ¶
View Source
const ( EncodingCBOR = "application/cbor" EncodingJSON = "application/json" EncodingJSONL = "application/jsonl" EncodingCAR = "application/vnd.ipld.car" EncodingMP4 = "video/mp4" EncodingANY = "*/*" )
Variables ¶
This section is empty.
Functions ¶
func BuildExtDefMap ¶
Build total map of all types defined inside schemas. Return map from fully qualified type name to its *TypeSchema
func CreateHandlerStub ¶
func FixRecordReferences ¶
TODO: this method is necessary because in lexicon there is no way to know if a type needs to be marshaled with a "$type" field up front, you can only know for sure by seeing where the type is used.
func GenCodeForSchema ¶
func WriteServerHandlers ¶
Types ¶
type ExtDef ¶
type ExtDef struct {
Type *TypeSchema
}
type InputType ¶
type InputType struct { Encoding string `json:"encoding"` Schema *TypeSchema `json:"schema"` }
type OutputType ¶
type OutputType struct { Encoding string `json:"encoding"` Schema *TypeSchema `json:"schema"` }
type Package ¶
type Package struct { GoPackage string `json:"package"` Prefix string `json:"prefix"` Outdir string `json:"outdir"` Import string `json:"import"` }
func ParsePackages ¶
ParsePackages reads a json blob which should be an array of Package{} objects.
type Schema ¶
type Schema struct { // Lexicon version, e.g. 1 Lexicon int `json:"lexicon"` ID string `json:"id"` Defs map[string]*TypeSchema `json:"defs"` // contains filtered or unexported fields }
Schema is a lexicon json file e.g. atproto/lexicons/app/bsky/feed/post.json https://atproto.com/specs/lexicon
func ReadSchema ¶
type TypeSchema ¶
type TypeSchema struct { Type string `json:"type"` Key string `json:"key"` Description string `json:"description"` Parameters *TypeSchema `json:"parameters"` Input *InputType `json:"input"` Output *OutputType `json:"output"` Record *TypeSchema `json:"record"` Ref string `json:"ref"` Refs []string `json:"refs"` Required []string `json:"required"` Nullable []string `json:"nullable"` Properties map[string]*TypeSchema `json:"properties"` MaxLength int `json:"maxLength"` Items *TypeSchema `json:"items"` Const any `json:"const"` Enum []string `json:"enum"` Closed bool `json:"closed"` Default any `json:"default"` Minimum any `json:"minimum"` Maximum any `json:"maximum"` // contains filtered or unexported fields }
TypeSchema is the content of a lexicon schema file "defs" section. https://atproto.com/specs/lexicon
func (*TypeSchema) TypeName ¶
func (s *TypeSchema) TypeName() string
func (*TypeSchema) WriteHandlerStub ¶
func (s *TypeSchema) WriteHandlerStub(w io.Writer, fname, shortname, impname string) error
func (*TypeSchema) WriteRPC ¶
func (s *TypeSchema) WriteRPC(w io.Writer, typename, inputname string) error
func (*TypeSchema) WriteRPCHandler ¶
func (s *TypeSchema) WriteRPCHandler(w io.Writer, fname, shortname, impname string) error
Click to show internal directories.
Click to hide internal directories.