seyfert

package module
v0.0.0-...-8cbc2af Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2016 License: MIT Imports: 13 Imported by: 0

README

seyfert

Template engine for Golang code.

THIS IS A ALPHA QUALITY RELEASE. API MAY CHANGE WITHOUT NOTICE.

Table of Contents

Install

$ go get github.com/mackee/seyfert

Usage

Source:

package main

import (
	"github.com/mackee/seyfert"
)

var tmpl = byte(`
package main

//+seyfert
type T_ struct {
	//+expand F
}

//+seyfert
func (t T_) String() string {
	return t.Name
}

`)

func main() {
	binds := seyfert.Binds{
		"T": "Person",
	}
	fiedsSet := seyfert.FieldsSet{
		"F": seyfert.Fields{
			seyfert.Field{
				Name: "Name",
				Type: "string",
				Tag:  `json:"name"`,
			},
			seyfert.Field{
				Name: "Age",
				Type: "int",
				Tag:  `json:"age"`,
			},
		},
	}
	err := seyfert.Render(tmpl, "person.gen.go", binds, fieldsSet, "main")
	if err != nil {
		panic(err)
	}
}

Generated File:

package main

//+seyfert
type Person struct {
	Name string `json:"name"`
	Age  string `json:"age"`
}

//+seyfert
func (t Person) String() string {
	return t.Name
}

See also: https://github.com/mackee/seyfert/blob/master/_example/genreqparser

Contribute

PRs accepted.

License

MIT © mackee

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(tmpl []byte, to string, binds Binds, fieldsSet FieldsSet, packageName string) error

Types

type Binds

type Binds map[string]string

type Field

type Field struct {
	Name string
	Type string
	Tag  string
}

func (Field) String

func (f Field) String() string

type Fields

type Fields []Field

func (Fields) String

func (fs Fields) String() string

type FieldsSet

type FieldsSet map[string]Fields

type Options

type Options struct {
	Binds Binds
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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