yamltmpl

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: MIT Imports: 8 Imported by: 0

README

YAML Templating Library for Golang

CircleCI

Introduction

yamltmpl uses text/template as internal template engine. Check its document for details.

Installation

go get github.com/Spiderpowa/yamltmpl

Example

package main

import (
    "bytes"
    "fmt"

    "github.com/Spiderpowa/yamltmpl"
)

func main() {
    tmpl := yamltmpl.New("test")
    tmpl, err := tmpl.Parse("host: {{.host}}\nport: {{.port}}\nname: it's a test")
    if err != nil {
        panic(err)
    }
    buf := new(bytes.Buffer)
    if err := tmpl.ApplyYaml([]byte("port: 3000\nhost: http://localhost"), buf); err != nil {
        panic(err)
    }
    fmt.Println(buf.String())
}

The output is

host: http://localhost
port: 3000
name: it's a test

Documentation

Godoc Template

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Funcs added in v0.3.0

func Funcs(funcs template.FuncMap)

Funcs adds the default function.

Types

type Template

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

Template is the parsed template structure.

func New

func New(name string) *Template

New creates a Template instance.

func (*Template) Apply

func (t *Template) Apply(rd io.Reader, wr io.Writer, overrides ...map[string]interface{}) error

Apply applies yaml input from Reader to the template and write its output to writer.

func (*Template) ApplyYaml

func (t *Template) ApplyYaml(in []byte, wr io.Writer, overrides ...map[string]interface{}) error

ApplyYaml applies yaml input to the template and write its output to writer.

func (*Template) Funcs

func (t *Template) Funcs(funcs template.FuncMap) *Template

Funcs adds the function to the template's function map.

func (*Template) Parse added in v0.2.0

func (t *Template) Parse(in string) (*Template, error)

Parse the template input.

func (*Template) ParseFile added in v0.2.0

func (t *Template) ParseFile(file string) (*Template, error)

ParseFile parses the file as the template input.

Jump to

Keyboard shortcuts

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