generator

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2018 License: MIT Imports: 12 Imported by: 0

README

Generator

Usage

Put a gommon.yml in folder, gommon will traverse folders and generate go file based on instruction

Supported generators

  • logger, generate methods to match log.LoggableStruct interface
  • go template, render template using text/template
loggers:
  - struct: "*Server"
    receiver: srv
gotmpls:
    - src: abc.go.tmpl
      dst: abc.go
      data:
        foo: bar

NOTE

  • remember to quote string with * in YAML, *Foo means reference while "*Foo" is a normal string

TODO

logger

gotmpl

  • replace Ayi's gotmpl

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(root string) error

func GenerateSingle

func GenerateSingle(file string) error
func Header(generator string, template string) string

func Walk

func Walk(root string, ignore Ignores) []string

Walk use dfs to find all gommon files TODO: limit level TODO: bfs using recursion?

func WriteFile

func WriteFile(f string, b []byte) error

WriteFile writes file using permission 0664 NOTE: 0664 is octal literal in Go, the code would compile for 664, but the result file mode is incorrect learned this the hard way https://github.com/dyweb/gommon/issues/41 stat -c %a pkg.go

Types

type Config

type Config struct {
	Loggers     []LoggerConfig     `yaml:"loggers"`
	GoTemplates []GoTemplateConfig `yaml:"gotmpls"`
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(pkg string, file string) *Config

func (*Config) Render

func (c *Config) Render() ([]byte, error)

func (*Config) RenderGoTemplate

func (c *Config) RenderGoTemplate(root string) error

type GoTemplateConfig

type GoTemplateConfig struct {
	Src  string      `yaml:"src"`
	Dst  string      `yaml:"dst"`
	Data interface{} `yaml:"data"`
}

func (*GoTemplateConfig) Render

func (c *GoTemplateConfig) Render(root string) error

type Ignores

type Ignores []string

func DefaultIgnores

func DefaultIgnores() Ignores

type LoggerConfig

type LoggerConfig struct {
	Struct   string `yaml:"struct"`
	Receiver string `yaml:"receiver"`
}

func (*LoggerConfig) RenderTo

func (c *LoggerConfig) RenderTo(w io.Writer) error

Jump to

Keyboard shortcuts

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