Documentation
¶
Overview ¶
Package bcl provides interpreting of the Basic Configuration Language (BCL) and storing the evaluated result in dynamic Blocks or static structs.
- Interpret or InterpretFile parses and executes definitions from a BCL file, then creates blocks and their binding
- Bind takes blocks binding and saves the content in static Go structs
- Unmarshal = Interpret + Bind
- UnmarshalFile = InterpretFile + Bind
It is also possible to first Parse, creating Prog, and then Execute it.
Prog can be dumped to a Writer with Dump and loaded with Load, there is also wrapper function LoadProg, to load previously dumped Prog instead of using Parse on the BCL input.
Index ¶
- func Bind(target any, binding Binding) error
- func Execute(prog *Prog, opts ...Option) (result []Block, binding Binding, err error)
- func Interpret(input []byte, opts ...Option) ([]Block, Binding, error)
- func InterpretFile(f FileInput, opts ...Option) ([]Block, Binding, error)
- func Unmarshal(input []byte, target any, opts ...Option) error
- func UnmarshalFile(f FileInput, target any, opts ...Option) error
- type Binding
- type Block
- type FileInput
- type Option
- type Prog
- type SliceBinding
- type StructBinding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
Bind binds the blocks selection (defined via binding) to the target. Target can be actually a struct or a slice of structs, and must correspond to a concrete Binding implementation, right now: StructBinding or SliceBinding.
When inside the struct (or the slice), the requirements are:
- struct type name should correspond to the BCL block type
- struct needs the Name string field
- for each block field, struct needs a corresponding field, of type as the evaluated value (currently supporting int, string and bool)
The mentioned name correspondence is similar to handling json: as BCL is expected to use snake case, and Go struct - capitalized camel case, the snake underscores are simply removed and then the strings are compared, case-insensitive.
The name corresponcence can be also set explicitly, by typing a tag keyed `bcl` at the struct field:
type Record struct {
Status string `bcl:"my_status"`
}
The lack of corresponding fields in the Go struct is reported as error. So is type mismatch of the fields.
If the binding type is a slice, and a slice pointed by target contained any elements, they are overwritten.
func InterpretFile ¶
InterpretFile reads, parses and executes the input from a BCL file. The file will be closed as soon as possible.
Types ¶
type Block ¶
Block is a dynamic result of running BCL Interpret. It can be put into a static structure via Bind.
type FileInput ¶
type FileInput interface {
io.ReadCloser
Name() string
}
FileInput abstracts the input that is read from a file. It is going to be closed as soon as it's read. The only information needed from a file besides reading/closing is that it has a name.
type Prog ¶
type Prog struct {
// contains filtered or unexported fields
}
type SliceBinding ¶
type SliceBinding struct{ Value []Block }
type StructBinding ¶
type StructBinding struct{ Value Block }