myrddin

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 23 Imported by: 0

README

Myrddin

GoDoc Go Report Card

A powerful yaml template engine for golang.

Usage

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

Example

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

Maintainers

  • Samy Fodil @samyfodil
  • Sam Stoltenberg @skelouse
  • Aron Jalbuena @arontaubyte

Documentation

Index

Constants

View Source
const (
	EnvironmentFileName = "/env.yaml"
)
View Source
const (
	Version = "0.9"
)

Variables

View Source
var ProcessingFileName = func() string {
	return "config.debug"
}
View Source
var (
	SpecialFiles = []string{EnvironmentFileName}
)

Functions

This section is empty.

Types

type EnvVariable

type EnvVariable struct {
	Name  string
	Value interface{}
}

type Environment added in v1.0.1

type Environment struct {
	*Myrddin
	// contains filtered or unexported fields
}

type EnvironmentFromYaml added in v1.0.1

type EnvironmentFromYaml map[string]interface{}

type Myrddin

type Myrddin struct {
	// contains filtered or unexported fields
}

func New

func New(tgt interface{}, options ...Option) (*Myrddin, error)

func (*Myrddin) AddModule

func (m *Myrddin) AddModule(p module.Module) error

func (*Myrddin) Environment added in v1.0.1

func (m *Myrddin) Environment() *Environment

func (*Myrddin) JsonLoader

func (m *Myrddin) JsonLoader(filename string) string

func (*Myrddin) Load

func (m *Myrddin) Load(uri string) error

func (*Myrddin) Loader

func (m *Myrddin) Loader(method string, filename string) string

func (*Myrddin) Parse

func (m *Myrddin) Parse(options ...ParseOption) error

func (*Myrddin) PngLoader

func (m *Myrddin) PngLoader(filename string) string

func (*Myrddin) ReadFile

func (m *Myrddin) ReadFile(uri string) ([]byte, error)

func (*Myrddin) Reader

func (m *Myrddin) Reader(filename string) string

func (*Myrddin) SvgLoader

func (m *Myrddin) SvgLoader(filename string) string

type Option

type Option func(m *Myrddin) error

func Data

func Data(name string, data interface{}) Option

func DefaultLoaders

func DefaultLoaders() Option

func Function

func Function(name string, f interface{}) Option

func Module

func Module(mod module.Module) Option

type ParseOption

type ParseOption Option

func Define

func Define(name string, data interface{}) ParseOption

type Plugin

type Plugin interface {
	Open(uri string) (io.Reader, error)
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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