ast

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2019 License: MIT Imports: 10 Imported by: 0

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

func FluxExtern(m ...interface{}) (*Extern, error)

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

func (e Extern) MarshalJSON() ([]byte, error)

MarshalJSON marshals an Extern so that flux can read it.

Jump to

Keyboard shortcuts

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