funi

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 7 Imported by: 0

README

funi

funi is template renderer with json/yaml data.

Install

go get github.com/kawaken/funi/cmd/funi

Usage

A template is passed via argument.

$ echo '{"key":"value"}' | funi "key is {{.key}}"
key is value

Use template file.

$ echo "key is {{.key}}" > key.tmpl
$ echo '{"key":"value"}' | funi -t key.tmpl
key is value
Template

Template syntax is from text/template.
template - The Go Programming Language

funi can handle multple template files. Use -t option multiple. Template are combined as one template.

$ echo "key: {{.key}}" > key2.tmpl 
$ echo '{"key":"value"}' | ./funi -t key.tmpl -t key2.tmpl
key is value
key: value
Options
$ funi -h
Usage of funi:
  -f string
      data format 'json' or 'yaml' (default "json")
  -i string
      input file (default STDIN)
  -o string
      output file (default STDOUT)
  -t string
      template file path (required)

-t is required when command line argument is nothing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(opts Options) error

Render renders template

Types

type Options

type Options struct {
	Format         string
	InputPath      string
	OutputPath     string
	TemplateString string
}

Options is option for rendering

type Renderer added in v1.0.3

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

Renderer renders data via template.

func NewRenderer added in v1.0.3

func NewRenderer(tmplText string) (*Renderer, error)

NewRenderer returns Renderer. If tmplText is invalid template, it returns error.

func (*Renderer) ExecuteJSON added in v1.0.3

func (ren *Renderer) ExecuteJSON(in io.Reader, out io.Writer) error

ExecuteJSON unmarshals data as json and applies a template to data.

func (*Renderer) ExecuteYAML added in v1.0.3

func (ren *Renderer) ExecuteYAML(in io.Reader, out io.Writer) error

ExecuteYAML unmarshals data as yaml and applies a template to data.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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