generator

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: MIT Imports: 13 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 DefaultIgnores

func DefaultIgnores() *fsutil.Ignores

func Generate

func Generate(root string) error

func GenerateSingle

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

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"`
	Go   bool        `yaml:"go"`
	Data interface{} `yaml:"data"`
}

func (*GoTemplateConfig) Render

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

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