Documentation
¶
Overview ¶
Package schema implements parsing of Go types into Encore's schema format.
Index ¶
- type BuiltinKind
- type BuiltinType
- type Decl
- type DeclKind
- type DeclTypeParam
- type FuncDecl
- type FuncType
- type InterfaceType
- type ListType
- type MapType
- type NamedType
- type Param
- type Parser
- type PointerType
- type Receiver
- type StructField
- type StructType
- type Type
- type TypeDecl
- type TypeDeclRef
- type TypeFamily
- type TypeParamRefType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuiltinKind ¶
type BuiltinKind int
const ( Invalid BuiltinKind = iota Any Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Float32 Float64 String Bytes Time UUID JSON UserID Error // builtin "error" type, for convenience )
func (BuiltinKind) String ¶
func (i BuiltinKind) String() string
type BuiltinType ¶
type BuiltinType struct {
AST ast.Expr
Kind BuiltinKind
}
func (BuiltinType) ASTExpr ¶
func (t BuiltinType) ASTExpr() ast.Expr
func (BuiltinType) Family ¶
func (BuiltinType) Family() TypeFamily
func (BuiltinType) String ¶
func (t BuiltinType) String() string
type Decl ¶
type Decl interface {
Kind() DeclKind
DeclaredIn() *pkginfo.File
// PkgName reports the name if this is a package-level declaration.
// Otherwise it reports None.
PkgName() option.Option[string]
// ASTNode returns the AST node that this declaration represents.
// It's a *ast.FuncDecl or *ast.TypeSpec.
ASTNode() ast.Node
// String returns the shorthand name for this declaration,
// in the form "pkgname.DeclName".
String() string
// TypeParameters are the type parameters on this declaration.
TypeParameters() []DeclTypeParam
}
Decl is the common interface for different kinds of declarations.
type DeclTypeParam ¶
type DeclTypeParam struct {
// AST is the AST node that this type param represents.
// Note that multiple fields may share the same *ast.Field node,
// in cases with multiple names, like "type Foo[A, B any]".
AST *ast.Field
Name string // the identifier given to the type parameter.
}
DeclTypeParam represents a type parameter on a declaration. For example A in "type Foo[A any] struct { ... }"
type FuncDecl ¶
type FuncDecl struct {
AST *ast.FuncDecl
File *pkginfo.File // the file declaring the type
Name string // the name of the function
Recv option.Option[*Receiver] // none if not a method
Type FuncType // signature
// TypeParams are any type parameters on this declaration.
// (note: instantiated types used within this declaration would not be captured here)
TypeParams []DeclTypeParam
}
A FuncDecl represents a function declaration.
func (*FuncDecl) DeclaredIn ¶
func (*FuncDecl) TypeParameters ¶
func (d *FuncDecl) TypeParameters() []DeclTypeParam
type InterfaceType ¶
type InterfaceType struct {
AST *ast.InterfaceType
// EmbeddedIfaces are the interfaces this interface embeds.
EmbeddedIfaces []Type
// TODO change these out for more useful information.
TypeLists []ast.Expr
Methods []*ast.Field
}
func (InterfaceType) ASTExpr ¶
func (t InterfaceType) ASTExpr() ast.Expr
func (InterfaceType) Family ¶
func (InterfaceType) Family() TypeFamily
func (InterfaceType) String ¶
func (t InterfaceType) String() string
type NamedType ¶
type NamedType struct {
AST ast.Expr // *ast.Ident or *ast.SelectorExpr
// DeclInfo is the declaration info for the declaration
// this refers to.
DeclInfo *pkginfo.PkgDeclInfo
// TypeArgs are the type arguments used to instantiate this named type.
TypeArgs []Type
// contains filtered or unexported fields
}
func (NamedType) Family ¶
func (NamedType) Family() TypeFamily
type Param ¶
type Param struct {
AST *ast.Field
Name option.Option[string] // parameter name, or None if a type-only parameter.
Type Type
}
Param represents a parameter or result field.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses Go types into Encore's schema format.
func (*Parser) ParseFuncDecl ¶
ParseFuncDecl parses the func from a package declaration. It errors if the type is not a func declaration.
func (*Parser) ParseTypeDecl ¶
func (p *Parser) ParseTypeDecl(d *pkginfo.PkgDeclInfo) *TypeDecl
ParseTypeDecl parses the type from a package declaration. It errors if the declaration is not a type.
type PointerType ¶
func (PointerType) ASTExpr ¶
func (t PointerType) ASTExpr() ast.Expr
func (PointerType) Family ¶
func (PointerType) Family() TypeFamily
func (PointerType) String ¶
func (t PointerType) String() string
type Receiver ¶
type Receiver struct {
AST *ast.FieldList
// Name is the name of the receiver (e.g. "a" in "func (a *Foo) Bar()").
// It's None if the receiver is unnamed (e.g. "func (*Foo) Bar()").
Name option.Option[string]
// Type is the type of the receiver.
// It's either a NamedType or a NamedType wrapped in a PointerType.
Type Type
// Decl is the underlying type declaration the receiver points to.
Decl *TypeDecl
}
A Receiver represents a method receiver. It describes the name and type of the receiver.
type StructField ¶
type StructField struct {
// AST is the AST node that this field represents.
// Note that multiple fields may share the same *ast.Field node,
// in cases with multiple names, like "Foo, Bar int".
AST *ast.Field
Name option.Option[string] // field name, or None if anonymous
Type Type
Doc string
Tag structtag.Tags
}
func (*StructField) IsAnonymous ¶
func (f *StructField) IsAnonymous() bool
func (*StructField) IsExported ¶
func (f *StructField) IsExported() bool
type StructType ¶
type StructType struct {
AST *ast.StructType
Fields []StructField
}
func (StructType) ASTExpr ¶
func (t StructType) ASTExpr() ast.Expr
func (StructType) Family ¶
func (StructType) Family() TypeFamily
func (StructType) String ¶
func (t StructType) String() string
type Type ¶
type Type interface {
Family() TypeFamily
ASTExpr() ast.Expr
String() string // Resolve to a string representation of the type.
}
type TypeDecl ¶
type TypeDecl struct {
// AST is the AST node that this declaration represents.
AST *ast.TypeSpec
Info *pkginfo.PkgDeclInfo // the underlying declaration info
File *pkginfo.File // the file declaring the type
Name string // name of the type declaration
Type Type // the declaration's underlying type
// TypeParams are any type parameters on this declaration.
// (note: instantiated types used within this declaration would not be captured here)
TypeParams []DeclTypeParam
}
TypeDecl represents a type declaration.
func (*TypeDecl) DeclaredIn ¶
func (*TypeDecl) TypeParameters ¶
func (d *TypeDecl) TypeParameters() []DeclTypeParam
type TypeDeclRef ¶
TypeDeclRef is a reference to a type declaration, through zero or more pointers and possibly with type arguments.
func (*TypeDeclRef) ToType ¶
func (r *TypeDeclRef) ToType() Type
type TypeFamily ¶
type TypeFamily int
const ( Unknown TypeFamily = iota Named Struct Map List Builtin Pointer Func Interface TypeParamRef )
type TypeParamRefType ¶
type TypeParamRefType struct {
AST *ast.Ident
Decl Decl // the declaration this type parameter is defined on
Index int // Index into the type parameter slice on the declaration
}
TypeParamRefType is a reference to a `TypeParameter` within a declaration block
func (TypeParamRefType) ASTExpr ¶
func (t TypeParamRefType) ASTExpr() ast.Expr
func (TypeParamRefType) Family ¶
func (TypeParamRefType) Family() TypeFamily
func (TypeParamRefType) String ¶
func (t TypeParamRefType) String() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package schematest provides utilities for writing tests that make assertions about schema types and declarations.
|
Package schematest provides utilities for writing tests that make assertions about schema types and declarations. |