easygen

package module
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 13 Imported by: 38

README

easygen

All Contributors

MIT License GoDoc Go Report Card Build Status PoweredBy WireFrame

The easy to use universal code/text generator

easygen is to json what xslt is to xml, but much more powerful and versatile.

easygen has been such a great help to us, making so many mundane tasks easier (and fun) to do.

TOC

easygen - Easy to use universal code/text generator

Command easygen is an easy to use universal code/text generator.

It can be used as a text or html generator for arbitrary purposes with arbitrary data and templates. It is a good GSL replacement, as it

  • is more easy to define driving data, in form of YML instead of XML
  • has more powerful template engine that based on Go template. You can also write your own function in Go to customize your template.
  • there are lots of transformation support functions builtin inside it, check out the full list with sample usages and results here.
  • apart from the above sample usages, it has extensive documentations like this. Check out the wiki for the full list.

You can even use easygen as a generic Go template testing tool using the -ts commandline option, and much more.

Note this document is for easygen versions 4.0+. For historic versions check out the Different Versions section.

Usage

$ easygen
easygen version 5.3.0

Usage:
 easygen [flags] template_name [data_filename [data_filename...]]

Flags:

  -debug level
    	debugging level
  -ej extension
    	extension of json file (default ".json")
  -et extension
    	extension of template file (default ".tmpl")
  -ey extension
    	extension of yaml file (default ".yaml")
  -ts string
    	template string (in text)

template_name: The name for the template file.
 - Can have the extension (specified by -et) or without it.
 - Can include the path as well.
 - Can be a comma-separated list giving many template files, in which case
   at least one data_filename must be given.

data_filename(s): The name for the .yaml or .json data.
 - If omitted derive from the template_name.
 - Can have the extension or without it. If withot extension,
   will try the .yaml file first then .json
 - Can include the path as well.
 - Can have more than one data files given on cli, separated by spaces,
   in which case multiple outputs will be produced based on the inputs.
 - Can be a comma-separated list giving many data files, in which case
   data will be merged together as if provided from a single file.
 - If there is a single data_filename, and it is "-",
   then read the data (.yaml or .json format) from stdin.

Flag defaults can be overridden by corresponding environment variable, e.g.:
  EASYGEN_EY=.yml EASYGEN_ET=.tpl easygen ...

Details

It can be used as a code generator, for example, command line parameter handling code generator, or anything that is structurally repetitive, like the following:

Ready to get started? Then check out Getting Started to start building your way to turn your data into any form, any way you want.

Install Debian/Ubuntu package

sudo apt install -y easygen

Download/install binaries

  • The latest binary executables are available as the result of the Continuous-Integration (CI) process.
  • I.e., they are built automatically right from the source code at every git release by GitHub Actions.
  • There are two ways to get/install such binary executables
    • Using the binary executables directly, or
    • Using packages for your distro
The binary executables
  • The latest binary executables are directly available under
    https://github.com/go-easygen/easygen/releases/latest
  • Pick & choose the one that suits your OS and its architecture. E.g., for Linux, it would be the easygen_verxx_linux_amd64.tar.gz file.
  • Available OS for binary executables are
    • Linux
    • Mac OS (darwin)
    • Windows
  • If your OS and its architecture is not available in the download list, please let me know and I'll add it.
  • The manual installation is just to unpack it and move/copy the binary executable to somewhere in PATH. For example,
tar -xvf easygen_*_linux_amd64.tar.gz
sudo mv -v easygen_*_linux_amd64/easygen /usr/local/bin/
rmdir -v easygen_*_linux_amd64
Distro package

The repo setup instruction url has been given above. For example, for Debian --

Debian package
curl -1sLf \
  'https://dl.cloudsmith.io/public/suntong/repo/setup.deb.sh' \
  | sudo -E bash

# That's it. You then can do your normal operations, like

sudo apt update
apt-cache policy easygen

sudo apt install -y easygen

Install Source

To install the source code instead:

go install github.com/go-easygen/easygen@latest

Author

Tong SUN
suntong from cpan.org

Powered by WireFrame
PoweredBy WireFrame
the one-stop wire-framing solution for Go cli based projects, from init to deploy.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


suntong

💻 🤔 🎨 🔣 ⚠️ 🐛 📖 📝 💡 🔧 📦 👀 💬 🚧 🚇

Gerrit Renker

💻 🤔 🐛 📓 📢 🖋 📝

Benjamin Ruston

💻 🐛 📓

sanjaymsh

📦

Anthony Fok

🐛 👀 🚧 📓

Deleted user

🐛 🤔 📓

Zbigniew Romanowski

🐛 🤔 📓

This project follows the all-contributors specification. Contributions of any kind welcome!

Documentation

Overview

Package easygen is an easy to use universal code/text generator library.

It can be used as a text or html generator for arbitrary purposes with arbitrary data and templates.

It can be used as a code generator, or anything that is structurally repetitive. Some command line parameter handling code generator are provided as examples, including the Go's built-in flag package, and the viper & cobra package.

Many examples have been provided to showcase its functionality, and different ways to use it.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Opts = Options{ExtYaml: ".yaml", ExtJson: ".json", ExtTmpl: ".tmpl"}

Opts holds the actual values from the command line parameters

Functions

func Add

func Add(b, a int) int

func ArgsA

func ArgsA(vs ...interface{}) []interface{}

ArgsA creates an array slice from the given arguments

func ArgsM

func ArgsM(kvs ...interface{}) (map[string]interface{}, error)

ArgsM creates a map from the given K/V argument pairs

func Coalesce

func Coalesce(s ...interface{}) string

Coalesce function takes two or more string arguments and returns the first argument that is not empty. The result is empty only if all the arguments are empty.

func Date

func Date(fmt string) string

Date returns the date or year

func Execute

func Execute(t Template, wr io.Writer, fileNameT string, m EgData) error

Execute will execute the Template from fileNameT on the given data map `m`.

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/go-easygen/easygen"
	"github.com/go-easygen/easygen/egCal"
	"github.com/go-easygen/easygen/egFilePath"
	"github.com/go-easygen/easygen/egVar"
)

func main() {
	easygen.Opts.Debug = 1

	tmpl0 := easygen.NewTemplate().Customize()
	tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egFilePath.FuncDefs()).
		Funcs(egVar.FuncDefs()).Funcs(egCal.FuncDefs())

	// define driving data
	v0 := easygen.EgData{"Name": "some-init-method"}
	// https://godoc.org/github.com/go-easygen/easygen#Execute
	// provide full template file name with extension
	easygen.Execute(tmpl, os.Stdout, "test/var0.tmpl", v0)

	// Demo of using driving data of slice/array
	v1 := easygen.EgData{"v": []string{"red", "blue", "white"}}
	easygen.Execute(tmpl, os.Stdout, "test/list00.tmpl", v1)

	// Demo output to string
	var b strings.Builder
	easygen.Execute(tmpl, &b, "test/list00f.tmpl", v1)
	fmt.Print(b.String())

}
Output:

Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"
The colors are: red, blue, white, .
The colors are: red, blue, white.

func Execute0

func Execute0(t Template, wr io.Writer, strTempl string, m EgData) error

Execute0 will execute the Template given as strTempl with the given data map `m` (i.e., no template file and no data file). It parses text template strTempl then applies it to to the specified data object m, and writes the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel, although if parallel executions share a Writer the output may be interleaved.

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/go-easygen/easygen"
)

// for standalone test, change package to `main` and the next func def to,
// func main() {
func main() {
	easygen.Opts.Debug = 1

	tmpl := easygen.NewTemplate().Funcs(easygen.FuncDefs())

	// define driving data
	v0 := easygen.EgData{"v": "some-init-method"}
	// https://godoc.org/github.com/go-easygen/easygen#Execute0
	// provide template string, not file name
	easygen.Execute0(tmpl, os.Stdout, "{{stringsToUpper .v}}\n", v0)

	// Demo of using driving data of slice/array
	v1 := easygen.EgData{"v": []string{"red", "blue", "white"}}
	easygen.Execute0(tmpl, os.Stdout, "The colors are: {{range .v}}{{.}}, {{end}}.\n", v1)

	// Demo output to string
	var b strings.Builder
	easygen.Execute0(tmpl, &b, "The colors are: {{range $i, $color := .v}}{{$color}}{{if lt $i ($.v | len | minus1)}}, {{end}}{{end}}.\n", v1)
	fmt.Print(b.String())

}

// To show the full code in GoDoc
type dummyExecute0 struct {
}
Output:

SOME-INIT-METHOD
The colors are: red, blue, white, .
The colors are: red, blue, white.

func FuncDefs

func FuncDefs() template.FuncMap

FuncDefs returns the custom definition mapping for this specific package.

func Indent

func Indent(spaces int, v string) string

Indent will indent the following lines according to the specified spaces

func IsExist

func IsExist(fileName string) bool

IsExist checks if the given file exist

func Iterate

func Iterate(ic ...string) []int

Iterate returns a slice whose end (& start) is controlled by the ic

func Minus

func Minus(b, a int) int

func Minus1

func Minus1(n int) int

Minus1 calculates to input less 1

func PIndent

func PIndent(spaces int, v string) string

PIndent will indent all lines according to the specified spaces

func Process

func Process(t Template, wr io.Writer, fileNames ...string) error

Process will process the standard easygen input: the `fileName` is for both template and data file name, and produce output from the template according to the corresponding driving data. Process() is using the V3's calling convention and *only* works properly in V4+ in the case that there is only one fileName passed to it. If need to pass more files, use Process2() instead.

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"os"

	"github.com/go-easygen/easygen"
	"github.com/go-easygen/easygen/egVar"
)

// for standalone test, change package to `main` and the next func def to,
// func main() {
func main() {
	tmpl0 := easygen.NewTemplate().Customize()
	tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egVar.FuncDefs())
	tmplFileName := "test/var0"
	easygen.Process(tmpl, os.Stdout, tmplFileName)
	easygen.Process2(tmpl, os.Stdout, tmplFileName, tmplFileName)

	// To use Execute(), TemplateFileName has to be exact
	m := easygen.ReadDataFile(tmplFileName + ".yaml")
	easygen.Execute(tmpl, os.Stdout, tmplFileName+".tmpl", m)

}

// To show the full code in GoDoc
type dummy struct {
}
Output:

Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"
Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"
Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"

func Process0

func Process0(t Template, wr io.Writer, strTempl string, fileNames ...string) error

Process0 will produce output according to the driving data *without* a template file, using the string from strTempl as the template

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"os"

	"github.com/go-easygen/easygen"
	"github.com/go-easygen/easygen/egCal"
	"github.com/go-easygen/easygen/egVar"
)

// for standalone test, change package to `main` and the next func def to,
// func main() {
func main() {
	tmpl0 := easygen.NewTemplate().Customize()
	tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egVar.FuncDefs()).Funcs(egCal.FuncDefs())
	easygen.Process0(tmpl, os.Stdout,
		"{{.Name}}: {{clk2uc .Name}} {{clk2ss .Name}}\n"+
			"Cal: {{add 2 3}}, {{multiply 2 3}}, {{subtract 9 2}}, {{divide 24 3}}\n",
		"test/var0")

}

// To show the full code in GoDoc
type dummy0 struct {
}
Output:

some-init-method: SomeInitMethod SOME_INIT_METHOD
Cal: 5, 6, 7, 8
Example (List0StrTemplate)

Test string template with list0 data

package main

import (
	"os"
	"text/template"

	"github.com/go-easygen/easygen"
)

var tmpl *template.Template

func main() {
	// Equivalent testing on commandline:
	//   easygen -ts '{{range .Colors}}{{.}}, {{end}}' test/list0
	easygen.Process0(tmpl, os.Stdout,
		"{{range .Colors}}{{.}}, {{end}}", "test/list0")
}
Output:

red, blue, white,
Example (Split0)

Test the string split function in template

package main

import (
	"os"
	"text/template"

	"github.com/go-easygen/easygen"
)

var tmpl *template.Template

func main() {
	// Equivalent testing on commandline:
	//   easygen -ts '{{split .Colorlist}}' test/list0
	easygen.Process0(tmpl, os.Stdout,
		`{{split .Colorlist}}`, "test/list0")
}
Output:

[red blue white]
Example (Split1)

Test the string split function in template again

package main

import (
	"os"
	"text/template"

	"github.com/go-easygen/easygen"
)

var tmpl *template.Template

func main() {
	// Equivalent testing on commandline:
	//   easygen -ts '{{range ... {{end}}' test/list0
	easygen.Process0(tmpl, os.Stdout,
		`{{range (split .Colorlist)}}{{.}} {{end}}`, "test/list0")
}
Output:

red blue white
Example (StringsCmp)

Test string comparison in template

package main

import (
	"os"
	"text/template"

	"github.com/go-easygen/easygen"
)

var tmpl *template.Template

func main() {
	// Equivalent testing on commandline:
	//   easygen -ts '{{The {{if ... {{end}}.' test/strings0
	easygen.Process0(tmpl, os.Stdout,
		`The {{if eq .StrTest "-AB-axxb- HTML Html html"}}eq says Yea{{else}}eq says Nay{{end}} but {{if eqf .StrTest "-AB-axxb- HTML Html html"}}eqf says Yea{{else}}eqf says Nay{{end}}.`, "test/strings0")
}
Output:

The eq says Nay but eqf says Yea.

func Process1

func Process1(t Template, wr io.Writer, fileNameTempl string, fileName string) error

Process1 will process a *single* case where both template and data file names are given, and produce output according to the given template and driving data files, specified via fileNameTempl and fileName respectively. fileNameTempl is not a comma-separated string, but for a single template file. However, the fileName can be a comma-separated string for multiple data files.

func Process2

func Process2(t Template, wr io.Writer, fileNameTempl string, fileNames ...string) error

Process2 will process the case that *both* template and data file names are given, and produce output according to the given template and driving data files, specified via fileNameTempl and fileNames respectively. fileNameTempl can be a comma-separated string giving many template files

Example (Html)

Test HTML template with list1 data

package main

import (
	"os"
	"text/template"

	"github.com/go-easygen/easygen"
)

var tmpl *template.Template

func main() {
	// Equivalent testing on commandline:
	//   easygen -tf test/list1HTML test/list1
	easygen.Process2(tmpl, os.Stdout, "test/list1HTML", "test/list1")
}
Output:

The quoted colors are: "red", "blue", "white", .

func Quote4shell

func Quote4shell(s string) string

Quote4shell -- quote file name for shell. So "%bob's file" will be quoted as '%bob'\”s file'

func RegexpFindAllString

func RegexpFindAllString(s string, regExp string, n int) []string

RegexpFindAllString is wrapper for regexp.FindAllString

func RegexpFindAllStringIndex

func RegexpFindAllStringIndex(s string, regExp string, n int) [][]int

RegexpFindAllStringIndex is wrapper for regexp.FindAllStringIndex

func RegexpFindAllStringSubmatch

func RegexpFindAllStringSubmatch(s string, regExp string, n int) [][]string

RegexpFindAllStringSubmatch is wrapper for regexp.FindAllStringSubmatch

func RegexpFindAllStringSubmatchIndex

func RegexpFindAllStringSubmatchIndex(s string, regExp string, n int) [][]int

RegexpFindAllStringSubmatchIndex is wrapper for regexp.FindAllStringSubmatchIndex

func RegexpFindString

func RegexpFindString(s string, regExp string) string

RegexpFindString is wrapper for regexp.FindString

func RegexpFindStringIndex

func RegexpFindStringIndex(s string, regExp string) (loc []int)

RegexpFindStringIndex is wrapper for regexp.FindStringIndex

func RegexpFindStringSubmatch

func RegexpFindStringSubmatch(s string, regExp string) []string

RegexpFindStringSubmatch is wrapper for regexp.FindStringSubmatch

func RegexpFindStringSubmatchIndex

func RegexpFindStringSubmatchIndex(s string, regExp string) []int

RegexpFindStringSubmatchIndex is wrapper for regexp.FindStringSubmatchIndex

func RegexpMatchString

func RegexpMatchString(s string, regExp string) bool

RegexpMatchString is wrapper for regexp.MatchString

func RegexpReplaceAllLiteralString

func RegexpReplaceAllLiteralString(src, regExp string, repl string) string

RegexpReplaceAllLiteralString is wrapper for regexp.ReplaceAllLiteralString

func RegexpReplaceAllString

func RegexpReplaceAllString(src, regExp string, repl string) string

RegexpReplaceAllString is wrapper for regexp.ReplaceAllString

func RegexpReplaceAllStringFunc

func RegexpReplaceAllStringFunc(src string, regExp string, repl func(string) string) string

RegexpReplaceAllStringFunc is wrapper for regexp.ReplaceAllStringFunc

func RegexpSplit

func RegexpSplit(s string, regExp string, n int) []string

RegexpSplit is wrapper for regexp.Split

func Substr

func Substr(a string, nums ...interface{}) (string, error)

Substr extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

It normally takes two parameters: start and length. It can also take one parameter: start, i.e. length is omitted, in which case the substring starting from start until the end of the string will be returned.

To extract characters from the end of the string, use a negative start number.

In addition, borrowing from the extended behavior described at http://php.net/substr, if length is given and is negative, then that many characters will be omitted from the end of string.

func Timestamp

func Timestamp(s ...string) (string, error)

Timestamp returns the current UNIX timestamp in UTC. If an argument is specified, it will be used to format the timestamp.

Types

type EgBase

type EgBase struct {
	*template.Template
}

EgBase -- EasyGen Template Base

stringsCompare is wrapper for strings.Compare
stringsContains is wrapper for strings.Contains
stringsContainsAny is wrapper for strings.ContainsAny
stringsContainsRune is wrapper for strings.ContainsRune
stringsCount is wrapper for strings.Count
stringsEqualFold is wrapper for strings.EqualFold
stringsFields is wrapper for strings.Fields
stringsFieldsFunc is wrapper for strings.FieldsFunc
stringsHasPrefix is wrapper for strings.HasPrefix
stringsHasSuffix is wrapper for strings.HasSuffix
stringsIndex is wrapper for strings.Index
stringsIndexAny is wrapper for strings.IndexAny
stringsIndexByte is wrapper for strings.IndexByte
stringsIndexFunc is wrapper for strings.IndexFunc
stringsIndexRune is wrapper for strings.IndexRune
stringsJoin is wrapper for strings.Join
stringsLastIndex is wrapper for strings.LastIndex
stringsLastIndexAny is wrapper for strings.LastIndexAny
stringsLastIndexByte is wrapper for strings.LastIndexByte
stringsLastIndexFunc is wrapper for strings.LastIndexFunc
stringsMap is wrapper for strings.Map
stringsRepeat is wrapper for strings.Repeat
stringsReplace is wrapper for strings.Replace
stringsSplit is wrapper for strings.Split
stringsSplitAfter is wrapper for strings.SplitAfter
stringsSplitAfterN is wrapper for strings.SplitAfterN
stringsSplitN is wrapper for strings.SplitN
stringsTitle is wrapper for strings.Title
stringsToLower is wrapper for strings.ToLower
stringsToLowerSpecial is wrapper for strings.ToLowerSpecial
stringsToTitle is wrapper for strings.ToTitle
stringsToTitleSpecial is wrapper for strings.ToTitleSpecial
stringsToUpper is wrapper for strings.ToUpper
stringsToUpperSpecial is wrapper for strings.ToUpperSpecial
stringsTrim is wrapper for strings.Trim
stringsTrimFunc is wrapper for strings.TrimFunc
stringsTrimLeft is wrapper for strings.TrimLeft
stringsTrimLeftFunc is wrapper for strings.TrimLeftFunc
stringsTrimPrefix is wrapper for strings.TrimPrefix
stringsTrimRight is wrapper for strings.TrimRight
stringsTrimRightFunc is wrapper for strings.TrimRightFunc
stringsTrimSpace is wrapper for strings.TrimSpace
stringsTrimSuffix is wrapper for strings.TrimSuffix

eqf is wrapper for strings.EqualFold
split is wrapper for strings.Fields
sprintf is wrapper for fmt.Sprintf

regexpFindAllString is template function for RegexpFindAllString
regexpFindAllStringIndex is template function for RegexpFindAllStringIndex
regexpFindAllStringSubmatch is template function for RegexpFindAllStringSubmatch
regexpFindAllStringSubmatchIndex is template function for RegexpFindAllStringSubmatchIndex
regexpFindString is template function for RegexpFindString
regexpFindStringIndex is template function for RegexpFindStringIndex
regexpFindStringSubmatch is template function for RegexpFindStringSubmatch
regexpFindStringSubmatchIndex is template function for RegexpFindStringSubmatchIndex
regexpMatchString is template function for RegexpMatchString
regexpReplaceAllLiteralString is template function for RegexpReplaceAllLiteralString
regexpReplaceAllString is template function for RegexpReplaceAllString
regexpReplaceAllStringFunc is template function for RegexpReplaceAllStringFunc
regexpSplit is template function for RegexpSplit

ENV is template function for os.Getenv
substr is template function for Substr
coalesce is template function for Coalesce
quote4shell is template function for Quote4shell

minus1 is template function for Minus1
date is template function for Date
timestamp is template function for Timestamp

func NewTemplate

func NewTemplate() *EgBase

NewTemplate returns a new Template for this specific package.

func (*EgBase) Customize

func (t *EgBase) Customize() *EgBase

Customize allows customization for this specific package.

type EgData

type EgData map[EgKey]interface{}

EgData, EasyGen driven Data

func ReadDataFile

func ReadDataFile(fileName string, ms ...EgData) EgData

ReadDataFile reads in the driving data from the given file, which can be optionally without the defined extension

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"os"

	"github.com/go-easygen/easygen"
	"github.com/go-easygen/easygen/egVar"
)

func main() {
	tmplFileName := "test/var0"
	tmpl0 := easygen.NewTemplate().Customize()
	tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egVar.FuncDefs())

	// To use Execute(), TemplateFileName has to be exact
	tmplFileNameFull := tmplFileName + ".tmpl"

	m := easygen.ReadDataFile(tmplFileName)
	easygen.Execute(tmpl, os.Stdout, tmplFileNameFull, m)

	easygen.Opts.Debug = 0
	m = easygen.ReadDataFile(tmplFileName + ".yaml")
	easygen.Execute(tmpl, os.Stdout, tmplFileNameFull, m)

	tmplFileName = "test/list0j"
	tmplFileNameFull = tmplFileName + ".tmpl"

	m = easygen.ReadDataFile(tmplFileName)
	easygen.Execute(tmpl, os.Stdout, tmplFileNameFull, m)

	m = easygen.ReadDataFile(tmplFileName + ".json")
	easygen.Execute(tmpl, os.Stdout, tmplFileNameFull, m)

}
Output:

Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"
Input: "some-init-method"
Output 1: "SomeInitMethod"
Output 2: "SOME_INIT_METHOD"
The colors are: red, blue, white, .
The colors are: red, blue, white, .

func ReadDataFiles

func ReadDataFiles(fileName string) EgData

ReadDataFiles reads in the driving data from the given file, which can be optionally without the defined extension, and can be a comma-separated string for multiple data files.

func ReadJsonFile

func ReadJsonFile(fileName string, ms ...EgData) EgData

ReadJsonFile reads given JSON file as EgData

func ReadYamlFile

func ReadYamlFile(fileName string, ms ...EgData) EgData

ReadYamlFile reads given YAML file as EgData

type EgKey

type EgKey = string

EgData, EasyGen key type

type FuncMap

type FuncMap map[string]interface{}

The FuncMap defined in easygen will shield the dependency of either text or html template, giving an implementation agnostic abstraction that will works for both cases.

type Options

type Options struct {
	TemplateStr string // template string (in text)
	ExtYaml     string // `extension` of yaml file
	ExtJson     string // `extension` of json file
	ExtTmpl     string // `extension` of template file
	Debug       int    // debugging `level`
}

The Options struct defines the structure to hold the commandline values

type Template

type Template interface {
	Execute(wr io.Writer, data interface{}) error
	ExecuteTemplate(wr io.Writer, name string, data interface{}) error
	Parse(text string) (*template.Template, error)
	ParseFiles(filenames ...string) (*template.Template, error)
	Name() string
}

The Template defines the common ground for both text and html Template

Directories

Path Synopsis
cmd
easygen
Command easygen is an easy to use universal code/text generator.
Command easygen is an easy to use universal code/text generator.
Package egCal provides generic calculation functionalities.
Package egCal provides generic calculation functionalities.
Package egFilePath provides filepath manupilation functionalities.
Package egFilePath provides filepath manupilation functionalities.
Package egVar provides variable naming functionalities.
Package egVar provides variable naming functionalities.

Jump to

Keyboard shortcuts

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