literals

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](errs *perr.List, literal *Struct, defaultValues *T) T

func ParseConstant

func ParseConstant(errs *perr.List, file *pkginfo.File, value ast.Expr) (rtn constant.Value)

func ParseString

func ParseString(node ast.Node) (string, bool)

ParseString parses the node as a string literal. If it's not a string literal it reports "", false.

func PrettyPrint

func PrettyPrint(node ast.Expr) string

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) ChildStruct

func (l *Struct) ChildStruct(fieldName string) (st *Struct, ok bool)

func (*Struct) ConstantValue

func (l *Struct) ConstantValue(fieldName string) constant.Value

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

func (l *Struct) DynamicFields() map[string]ast.Expr

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

func (l *Struct) Expr(fieldName string) ast.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

func (l *Struct) FieldPaths() []string

FieldPaths reports all field paths in the struct, recursively including child structs (in the `parent.child` syntax).

func (*Struct) FullyConstant

func (l *Struct) FullyConstant() bool

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

func (l *Struct) Int64(fieldName string, defaultValue int64) 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 (l *Struct) IsConstant(fieldName string) bool

func (*Struct) IsSet

func (l *Struct) IsSet(fieldName string) bool

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

func (l *Struct) Pos(fieldName string) token.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`

func (*Struct) Str

func (l *Struct) Str(fieldName string, defaultValue string) string

Str returns the value of the field as an string

This function will convert all types to a string If after conversion the value is "", the defaultValue will be returned

You can reference a child struct field with `.`; i.e. `parent.child`

Jump to

Keyboard shortcuts

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