parser

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonTag

type JsonTag struct {
	Name      string
	Value     string
	IsString  bool
	Omitempty bool
	Inline    bool
}

func GetJsonTag

func GetJsonTag(structTags string) (JsonTag, bool)

type Parser

type Parser struct {
	Schema *schema.WebRPCSchema

	// Cache parsed types to improve performance and so we can traverse circular dependencies.
	ParsedTypes map[types.Type]*schema.VarType

	ParsedEnumTypes map[string]*schema.Type // Helps lookup enum types by pkg easily.

	InlineMode    bool // When traversing `json:",inline"`, we don't want to store the struct type as WebRPC message.
	ImportedPaths map[string]struct{}

	SchemaPkgName string // Schema file's package name.

	Pkg *packages.Package
}

Parses Go source file and returns WebRPC Schema.

This Parser was designed to run sequentially, without any concurrency, so we can leverage maps to cache the already parsed types, while not having to deal with sync primitives.

func New added in v0.7.2

func New(pkg *packages.Package) *Parser

func (*Parser) CollectEnums

func (p *Parser) CollectEnums() error

CollectEnums collects ENUM definitions, ie.:

// approved = 0
// pending  = 1
// closed   = 2
// new      = 3
type Status gospeak.Enum[int]

func (*Parser) GoTypeImport

func (p *Parser) GoTypeImport(typ types.Type) string

func (*Parser) GoTypeName

func (p *Parser) GoTypeName(typ types.Type) string

func (*Parser) GoTypeNameToWebrpc added in v0.7.6

func (p *Parser) GoTypeNameToWebrpc(typ string) string

func (*Parser) ParseAny

func (p *Parser) ParseAny(typeName string, iface *types.Interface) (*schema.VarType, error)

func (*Parser) ParseBasic

func (p *Parser) ParseBasic(typ *types.Basic) (*schema.VarType, error)

func (*Parser) ParseInterfaceMethods

func (p *Parser) ParseInterfaceMethods(iface *types.Interface, name string) error

func (*Parser) ParseMap

func (p *Parser) ParseMap(typeName string, m *types.Map) (*schema.VarType, error)

func (*Parser) ParseNamedType

func (p *Parser) ParseNamedType(goTypeName string, typ types.Type) (varType *schema.VarType, err error)

func (*Parser) ParseSlice

func (p *Parser) ParseSlice(typeName string, sliceTyp *types.Slice) (*schema.VarType, error)

func (*Parser) ParseStruct

func (p *Parser) ParseStruct(goTypeName string, structTyp *types.Struct) (*schema.VarType, error)

func (*Parser) ParseType

func (p *Parser) ParseType(typ types.Type) (*schema.VarType, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL