Documentation ¶
Index ¶
- func IsAny(typ types.Type) bool
- func IsClass(typ types.Type) bool
- func IsDirective(comment string, directive string) bool
- func IsJSONMarshaler(typ types.Type) bool
- func IsMapKey(typ types.Type) bool
- func IsString(typ types.Type) bool
- func IsTextMarshaler(typ types.Type) bool
- func MaybeJSONMarshaler(typ types.Type) bool
- func MaybeTextMarshaler(typ types.Type) bool
- func ParseDirective(comment string, directive string) string
- type Collector
- func (collector *Collector) Const(obj *types.Const) *ConstInfo
- func (collector *Collector) Field(obj *types.Var) *FieldInfo
- func (collector *Collector) Iterate(yield func(pkg *PackageInfo) bool)
- func (collector *Collector) Method(obj *types.Func) *MethodInfo
- func (collector *Collector) Model(obj *types.TypeName) *ModelInfo
- func (collector *Collector) Package(pkg *types.Package) *PackageInfo
- func (collector *Collector) Service(obj *types.TypeName) *ServiceInfo
- func (collector *Collector) Struct(typ *types.Struct) *StructInfo
- func (collector *Collector) Type(obj *types.TypeName) *TypeInfo
- type Condition
- type ConstInfo
- type FieldInfo
- type GroupInfo
- type ImportInfo
- type ImportMap
- type Info
- type MethodInfo
- type ModelFieldInfo
- type ModelInfo
- type PackageIndex
- type PackageInfo
- type ParamInfo
- type Scheduler
- type ServiceInfo
- type ServiceMethodInfo
- type Stats
- type StructField
- type StructInfo
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClass ¶
IsClass returns true if the given type will be rendered as a JS/TS model class (or interface).
func IsDirective ¶
IsDirective returns true if the given comment is a directive of the form //wails: + directive.
func IsJSONMarshaler ¶
IsJSONMarshaler tests whether the given type implements the json.Marshaler interface.
func IsString ¶
IsString returns true if the given type (or element type for pointers) will be rendered as an alias for the TS string type.
func IsTextMarshaler ¶
IsTextMarshaler tests whether the given type implements the encoding.TextMarshaler interface.
func MaybeJSONMarshaler ¶
MaybeJSONMarshaler tests whether the given type implements the json.Marshaler interface for at least one receiver form.
func MaybeTextMarshaler ¶
MaybeTextMarshaler tests whether the given type implements the encoding.TextMarshaler interface for at least one receiver form.
func ParseDirective ¶
ParseDirective extracts the argument portion of a //wails: + directive comment.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector wraps all bookkeeping data structures that are needed to collect data about a set of packages, bindings and models.
func NewCollector ¶
func NewCollector(pkgs []*packages.Package, systemPaths *config.SystemPaths, options *flags.GenerateBindingsOptions, scheduler Scheduler, logger config.Logger) *Collector
NewCollector initialises a new Collector instance for the given package set.
func (*Collector) Const ¶
Const returns the unique ConstInfo instance associated to the given object within a collector.
Const is safe for concurrent use.
func (*Collector) Field ¶
Field returns the unique FieldInfo instance associated to the given object within a collector.
Field is safe for concurrent use.
func (*Collector) Iterate ¶
func (collector *Collector) Iterate(yield func(pkg *PackageInfo) bool)
Iterate calls yield sequentially for each PackageInfo instance registered with the collector. If yield returns false, Iterate stops the iteration.
Iterate is safe for concurrent use.
func (*Collector) Method ¶
func (collector *Collector) Method(obj *types.Func) *MethodInfo
Method returns the unique MethodInfo instance associated to the given object within a collector.
Method is safe for concurrent use.
func (*Collector) Model ¶
Model retrieves the the unique ModelInfo instance associated to the given type object within a Collector. If none is present, Model initialises a new one registers it for code generation and schedules background collection activity.
Model is safe for concurrent use.
func (*Collector) Package ¶
func (collector *Collector) Package(pkg *types.Package) *PackageInfo
Package retrieves the the unique PackageInfo instance, if any, associated to the given package object within a Collector.
Package is safe for concurrent use.
func (*Collector) Service ¶
func (collector *Collector) Service(obj *types.TypeName) *ServiceInfo
Service returns the unique ServiceInfo instance associated to the given object within a collector and registers it for code generation.
Service is safe for concurrent use.
func (*Collector) Struct ¶
func (collector *Collector) Struct(typ *types.Struct) *StructInfo
Struct retrieves the unique StructInfo instance associated to the given type within a Collector. If none is present, a new one is initialised.
Struct is safe for concurrent use.
type Condition ¶
func ParseCondition ¶
ParseCondition parses an optional two-character condition prefix for include or inject directives. It returns the argument stripped of the prefix and the resulting condition. If the condition is malformed, ParseCondition returns a non-nil error.
type ConstInfo ¶
type ConstInfo struct { Name string Value any Pos token.Pos Spec *GroupInfo Decl *GroupInfo // contains filtered or unexported fields }
ConstInfo records information about a constant declaration.
Read accesses to any public field are only safe if a call to ConstInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*ConstInfo) Collect ¶
Collect gathers information about the constant described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
type FieldInfo ¶
type FieldInfo struct { Name string Blank bool Embedded bool Pos token.Pos Decl *GroupInfo // contains filtered or unexported fields }
FieldInfo records information about a struct field declaration.
Read accesses to any public field are only safe if a call to FieldInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*FieldInfo) Collect ¶
Collect gathers information about the struct field described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
type GroupInfo ¶
type GroupInfo struct { Pos token.Pos Doc *ast.CommentGroup // contains filtered or unexported fields }
GroupInfo records information about a group of type, field or constant declarations. This may be either a list of distinct specifications wrapped in parentheses, or a single specification declaring multiple fields or constants.
Read accesses to any public field are only safe if a call to GroupInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*GroupInfo) Collect ¶
Collect gathers information about the declaration group described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
type ImportInfo ¶
type ImportInfo struct { Name string Index int // Progressive number for identically named imports, starting from 0 for each distinct name. RelPath string }
ImportInfo records information about a single import.
type ImportMap ¶
type ImportMap struct { // Self records the path of the importing package. Self string // ImportModels records whether models from the current package may be needed. ImportModels bool // ImportInternal records whether internal models from the current package may be needed. ImportInternal bool // External records information about each imported package, // keyed by package path. External map[string]ImportInfo // contains filtered or unexported fields }
ImportMap records deduplicated imports by a binding or models module. It computes relative import paths and assigns import names, taking care to avoid collisions.
func NewImportMap ¶
func NewImportMap(importer *PackageInfo) *ImportMap
NewImportMap initialises an import map for the given importer package. The argument may be nil, in which case import paths will be relative to the root output directory.
func (*ImportMap) Add ¶
func (imports *ImportMap) Add(pkg *PackageInfo)
Add adds the given package to the import map if not already present, choosing import names so as to avoid collisions.
Add does not support unsynchronised concurrent calls on the same receiver.
func (*ImportMap) AddType ¶
AddType adds all dependencies of the given type to the import map and marks all referenced named types as models.
It is a runtime error to call AddType on an ImportMap created with nil importing package.
AddType does not support unsynchronised concurrent calls on the same receiver.
type Info ¶
Info instances provide information about either a type-checker object, a struct type or a group of declarations.
type MethodInfo ¶
type MethodInfo struct { Name string // Abstract is true when the described method belongs to an interface. Abstract bool Doc *ast.CommentGroup Decl *GroupInfo // contains filtered or unexported fields }
MethodInfo records information about a method declaration.
Read accesses to any public field are only safe if a call to MethodInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*MethodInfo) Collect ¶
func (info *MethodInfo) Collect() *MethodInfo
Collect gathers information about the method described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
func (*MethodInfo) Node ¶
func (info *MethodInfo) Node() ast.Node
func (*MethodInfo) Object ¶
func (info *MethodInfo) Object() types.Object
func (*MethodInfo) Type ¶
func (info *MethodInfo) Type() types.Type
type ModelFieldInfo ¶
type ModelFieldInfo struct { *StructField *FieldInfo }
ModelFieldInfo holds extended information about a struct field in a model type.
type ModelInfo ¶
type ModelInfo struct { *TypeInfo // Imports records dependencies for this model. Imports *ImportMap // Type records the target type for an alias or derived model, // the underlying type for an enum. Type types.Type // Fields records the property list for a class or struct alias model, // in order of declaration and grouped by their declaring [ast.Field]. Fields [][]*ModelFieldInfo // Values records the value list for an enum model, // in order of declaration and grouped // by their declaring [ast.GenDecl] and [ast.ValueSpec]. Values [][][]*ConstInfo // TypeParams records type parameter names for generic models. TypeParams []string // contains filtered or unexported fields }
ModelInfo records all information that is required to render JS/TS code for a model type.
Read accesses to exported fields are only safe if a call to ModelInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*ModelInfo) Collect ¶
Collect gathers information for the model described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
type PackageIndex ¶
type PackageIndex struct { Package *PackageInfo Services []*ServiceInfo Models []*ModelInfo Internal []*ModelInfo }
PackageIndex lists all bindings, models and unexported models generated from a package.
When obtained through a call to PackageInfo.Index, each binding and model name appears at most once.
func (*PackageIndex) IsEmpty ¶
func (index *PackageIndex) IsEmpty() bool
IsEmpty returns true if the given index contains no data for the selected language.
type PackageInfo ¶
type PackageInfo struct { // Path holds the canonical path of the described package. Path string // Name holds the import name of the described package. Name string // Types and TypesInfo hold type information for this package. Types *types.Package TypesInfo *types.Info // Fset holds the FileSet that was used to parse this package. Fset *token.FileSet // Files holds parsed files for this package, // ordered by start position to support binary search. Files []*ast.File // Docs holds package doc comments. Docs []*ast.CommentGroup // Includes holds a list of additional files to include // with the generated bindings. // It maps file names to their paths on disk. Includes map[string]string // Injections holds a list of code lines to be injected // into the package index file. Injections []string // contains filtered or unexported fields }
PackageInfo records information about a package.
Read accesses to fields Path, Name, Types, TypesInfo, Fset are safe at any time without any synchronisation.
Read accesses to all other fields are only safe if a call to PackageInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
Concurrent write accesses are only allowed through the provided methods.
func (*PackageInfo) Collect ¶
func (info *PackageInfo) Collect() *PackageInfo
Collect gathers information about the package described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
func (*PackageInfo) Index ¶
func (info *PackageInfo) Index(TS bool) (index *PackageIndex)
Index computes a PackageIndex for the selected language from the list of generated services and models and regenerates cached stats.
Services and models appear at most once in the returned slices, which are sorted by name.
Index calls info.Collect, and therefore provides the same guarantees. It is safe for concurrent use.
func (*PackageInfo) Stats ¶
func (info *PackageInfo) Stats() *Stats
Stats returns cached statistics for this package. If PackageInfo.Index has not been called yet, it returns nil.
Stats is safe for unsynchronised concurrent calls.
type ParamInfo ¶
ParamInfo records all information that is required to render JS/TS code for a service method parameter.
type Scheduler ¶
type Scheduler interface { // Schedule should run the given function according // to the implementation's preferred strategy. // // Scheduled tasks may call Schedule again; // therefore, if tasks run concurrently, // the implementation must support concurrent calls. Schedule(task func()) }
Scheduler instances provide task scheduling for collection activities.
type ServiceInfo ¶
type ServiceInfo struct { *TypeInfo Imports *ImportMap Methods []*ServiceMethodInfo // Injections stores a list of JS code lines // that should be injected into the generated file. Injections []string // contains filtered or unexported fields }
ServiceInfo records all information that is required to render JS/TS code for a service type.
Read accesses to any public field are only safe if a call to ServiceInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*ServiceInfo) Collect ¶
func (info *ServiceInfo) Collect() *ServiceInfo
Collect gathers information about the service described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
func (*ServiceInfo) IsEmpty ¶
func (info *ServiceInfo) IsEmpty() bool
IsEmpty returns true if no methods or code injections are present for this service, for the selected language.
type ServiceMethodInfo ¶
type ServiceMethodInfo struct { *MethodInfo FQN string ID string Internal bool Params []*ParamInfo Results []types.Type }
ServiceMethodInfo records all information that is required to render JS/TS code for a service method.
type Stats ¶
type StructField ¶
type StructField struct { JsonName string // Avoid collisions with [FieldInfo.Name]. Type types.Type Optional bool Quoted bool // Object holds the described type-checker object. Object *types.Var }
FieldInfo represents a single field in a struct.
type StructInfo ¶
type StructInfo struct { Fields []*StructField // contains filtered or unexported fields }
StructInfo records the flattened field list for a struct type, taking into account JSON tags.
The field list is initially empty. It will be populated upon calling StructInfo.Collect for the first time.
Read accesses to the field list are only safe if a call to StructInfo.Collect has been completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*StructInfo) Collect ¶
func (info *StructInfo) Collect() *StructInfo
Collect gathers information for the structure described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
The field list of the receiver is populated by the same flattening algorithm employed by encoding/json. JSON struct tags are accounted for.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
func (*StructInfo) Node ¶
func (*StructInfo) Node() ast.Node
func (*StructInfo) Object ¶
func (*StructInfo) Object() types.Object
func (*StructInfo) Type ¶
func (info *StructInfo) Type() types.Type
type TypeInfo ¶
type TypeInfo struct { Name string // Alias is true for type aliases. Alias bool Doc *ast.CommentGroup Decl *GroupInfo // Def holds the actual denotation of the type expression // that defines the described type. // This is not the same as the underlying type, // which skips all intermediate aliases and named types. Def types.Type // contains filtered or unexported fields }
TypeInfo records information about a type declaration.
Read accesses to any public field are only safe if a call to TypeInfo.Collect has completed before the access, for example by calling it in the accessing goroutine or before spawning the accessing goroutine.
func (*TypeInfo) Collect ¶
Collect gathers information about the type described by its receiver. It can be called concurrently by multiple goroutines; the computation will be performed just once.
Collect returns the receiver for chaining. It is safe to call Collect with nil receiver.
After Collect returns, the calling goroutine and all goroutines it might spawn afterwards are free to access the receiver's fields indefinitely.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This example explores exhaustively the behaviour of encoding/json when handling types that implement marshaler interfaces.
|
This example explores exhaustively the behaviour of encoding/json when handling types that implement marshaler interfaces. |