generator

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 4, 2018 License: MIT Imports: 15 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
  • shell, call external commands like protoc
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

shell

  • support using sh -c

Documentation

Overview

Package generator render go template, call external commands, generate gommon specific methods based on gommon.yml

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

Types

type Config

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

func NewConfig

func NewConfig(pkg string, file string) *Config

func (*Config) RenderGoTemplate

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

func (*Config) RenderGommon added in v0.0.5

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

func (*Config) RenderShell added in v0.0.5

func (c *Config) RenderShell(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

type ShellConfig added in v0.0.5

type ShellConfig struct {
	Code  string `yaml:"code"`
	Shell bool   `yaml:"shell"`
	Cd    bool   `yaml:"cd"`
}

https://github.com/dyweb/gommon/issues/53

func (*ShellConfig) Render added in v0.0.5

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

Jump to

Keyboard shortcuts

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