Documentation ¶
Overview ¶
Package ast provides tools for manipulating the flux ast. Eventually this will become a builder api.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extern ¶
type Extern struct {
Body []variableAssignment `json:"body"`
}
Extern is what we use to marshal something that will get unmarshaled in flux as an ast.File.
func FluxExtern ¶
FluxExtern is a function that generates an extern given a struct or map[string]<whatever>. It reflects over the object to generate variables.
Example (Map) ¶
buf := &strings.Builder{} enc := json.NewEncoder(buf) ext, err := FluxExtern(map[string]string{ "bucket": "my-bucket", }) if err != nil { log.Fatal(err) } if err := enc.Encode(ext); err != nil { log.Fatal(err) } fmt.Println(buf.String())
Output: {"type":"File","body":[{"type":"VariableAssignment","id":{"type":"Identifier","name":"bucket"},"init":{"type":"StringLiteral","value":"my-bucket"}}]}
Example (Struct) ¶
buf := &strings.Builder{} enc := json.NewEncoder(buf) ext, err := FluxExtern(struct { Bucket string `flux:"bucket"` OtherVariable string `flux:"otherVariable,omitempty"` }{ Bucket: "my-bucket", }) if err != nil { log.Fatal(err) } if err := enc.Encode(ext); err != nil { log.Fatal(err) } fmt.Println(buf.String())
Output: {"type":"File","body":[{"type":"VariableAssignment","id":{"type":"Identifier","name":"bucket"},"init":{"type":"StringLiteral","value":"my-bucket"}}]}
func (Extern) MarshalJSON ¶
MarshalJSON marshals an Extern so that flux can read it.
Click to show internal directories.
Click to hide internal directories.