Documentation ¶
Index ¶
- func Decode[T any](errs *perr.List, literal *Struct, defaultValues *T) T
- func ParseConstant(errs *perr.List, file *pkginfo.File, value ast.Expr) (rtn constant.Value)
- func ParseString(node ast.Node) (string, bool)
- func PrettyPrint(node ast.Expr) string
- type Struct
- func (l *Struct) ChildStruct(fieldName string) (st *Struct, ok bool)
- func (l *Struct) ConstantValue(fieldName string) constant.Value
- func (l *Struct) DynamicFields() map[string]ast.Expr
- func (l *Struct) Expr(fieldName string) ast.Expr
- func (l *Struct) FieldPaths() []string
- func (l *Struct) FullyConstant() bool
- func (l *Struct) Int64(fieldName string, defaultValue int64) int64
- func (l *Struct) IsConstant(fieldName string) bool
- func (l *Struct) IsSet(fieldName string) bool
- func (l *Struct) Lit() *ast.CompositeLit
- func (l *Struct) Pos(fieldName string) token.Pos
- func (l *Struct) Str(fieldName string, defaultValue string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseConstant ¶
func ParseString ¶
ParseString parses the node as a string literal. If it's not a string literal it reports "", false.
func PrettyPrint ¶
Types ¶
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct represents a struct literal at compile time
func ParseStruct ¶
func ParseStruct(errs *perr.List, file *pkginfo.File, expectedType string, node ast.Expr) (lit *Struct, ok bool)
ParseStruct parses struct literal and returns a LiterialStruct object
If there is a nested struct literal, then it's values will be nested in a dot syntax; i.e. `parentStructFieldName.childStructFieldName`
func (*Struct) ConstantValue ¶
ConstantValue returns the value of the field as a constant.Value. If the field is not constant or does not exist, an unknown value will be returned
You can reference a child struct field with `.`; i.e. `parent.child`
func (*Struct) DynamicFields ¶
DynamicFields returns the names of the fields and ast.Expr that are not constant
Child structs will be included with the field name prefixed with the struct name; i.e. `parentField.childField`
func (*Struct) Expr ¶
Expr returns ast.Expr for the given field name.
If the field is known, it returns the ast.Expr If the field is not known, it returns nil
You can reference a child struct field with `.`; i.e. `parent.child`
func (*Struct) FieldPaths ¶
FieldPaths reports all field paths in the struct, recursively including child structs (in the `parent.child` syntax).
func (*Struct) FullyConstant ¶
FullyConstant returns true if every value in this struct and the child structs fully known as compile time as a constant value
func (*Struct) Int64 ¶
Int64 returns the value of the field as an int64
This function will convert other number types into an Int64, but will not convert strings. If after conversion the value is 0, the defaultValue will be returned
You can reference a child struct field with `.`; i.e. `parent.child`
func (*Struct) IsConstant ¶
func (*Struct) IsSet ¶
IsSet returns true if the given field is set in this struct
You can reference a child struct field with `.`; i.e. `parent.child`
func (*Struct) Lit ¶
func (l *Struct) Lit() *ast.CompositeLit
func (*Struct) Pos ¶
Pos returns the position of the field in the source code
If the field is not found, the closest position to where the field should have been will be returned
You can reference a child struct field with `.`; i.e. `parent.child`