A powerful yaml template engine for golang.
Import
import "github.com/taubyte/myrddin"
Define a struct that will receive the data. Example:
type MyConfig struct {
Hostname string `yaml:"host"`
Shell string `yaml:"shell"`
Name string `yaml:"name"`
Networks []struct {
Name string `yaml:"name"`
AddrRange struct {
Start string `yaml:"start"`
End string `yaml:"end"`
} `yaml:"addr_range"`
} `yaml:"networks"`
}
Create a myrddin instance and pass the recipient struct as an argument
config := &MyConfig{}
m, err := myrddin.New(config)
You can aslo pass custom data and function as options
m, err := myrddin.New(
config,
myrddin.Data(
"ver",
[]string{"v0.0.1"},
),
myrddin.Function(
"unixTime",
func() { return time.Now().Unix() },
),
)
Then, load the folder containing your files
err = m.Load("config")
Finally, parse:
err = m.Parse()
cd example
go run .
Output should look like
host: hostname
shell: /bin/bash
name: test
networks:
- name: net0
addr_range:
start: 192.168.0.1
end: 192.178.0.100
- name: net1
addr_range:
start: 192.168.1.1
end: 192.178.1.100
- name: net2
addr_range:
start: 192.168.2.1
end: 192.178.2.100
- Samy Fodil @samyfodil
- Sam Stoltenberg @skelouse
- Aron Jalbuena @arontaubyte