generator

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: MIT Imports: 16 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
  • noodle, bundle assets into a single go file with a huge []byte as gzipped data
loggers:
- struct: "*Server"
  receiver: srv
gotmpls:
- src: abc.go.tmpl
  dst: abc.go
  data:
    foo: bar
shells:
# copy version.go since it's same for all binaries
- code: echo gnse2e gnsmock | xargs -n 1 cp gnsdev/version.go
  shell: true
  cd: true
noodles:
- root: "assets"
  export_name: "Assets"

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

View Source
const (
	// PkgName TODO: is reserved for the incoming library package (liblibrary?) to allow control logger etc.
	PkgName              = "gommon"
	GommonConfigFile     = "gommon.yml"
	Name                 = "gommon"
	DefaultGeneratedFile = "gommon_generated.go"
)

Variables

This section is empty.

Functions

func DefaultIgnores

func DefaultIgnores() *fsutil.Ignores

func Generate

func Generate(root string) error

Generate walks all sub directories and generate files based on gommon.yml

func GenerateSingle

func GenerateSingle(file string) error

GenerateSingle generates based on a single gommon.yml

Types

type ConfigFile added in v0.0.8

type ConfigFile struct {
	// Loggers is helper methods on struct for gommon/log to build a tree for logger, this is subject to change
	Loggers []dlog.StructLoggerConfig `yaml:"loggers"`
	// GoTemplates is templates written in go's text/template format, they are mainly used to generate go source file
	GoTemplates []GoTemplateConfig `yaml:"gotmpls"`
	// Noodles is the config for embedding assets by generating go file with a large byte slice
	Noodles []noodle.EmbedConfig `yaml:"noodles"`
	// Shells is shell commands to be executed
	Shells []ShellConfig `yaml:"shells"`
	// GoPackage override folder name for generated go file
	GoPackage string `yaml:"go_package"`
	// contains filtered or unexported fields
}

func NewConfigFile added in v0.0.8

func NewConfigFile(pkg string, file string) *ConfigFile

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 ShellConfig added in v0.0.5

type ShellConfig struct {
	// Code is the command to be executed, Command will overwrite it if presented,
	// it is kept for backward compatibility
	Code    string `yaml:"code"`
	Command string `yaml:"command"`

	// Shell is true, use sh -c, otherwise use exec on the first segment after split
	Shell bool `yaml:"shell"`
	// Cd is true, switch to the folder of config file when executing command
	Cd bool `yaml:"cd"`
}

ShellConfig is shell command executed by gommon https://github.com/dyweb/gommon/issues/53

func (*ShellConfig) Render added in v0.0.5

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

Render execute the shell command, redirect stdin/out/err and block until it is finished

Jump to

Keyboard shortcuts

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