gengo

package
v0.0.0-...-dbc29b6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LowerCamelCase

func LowerCamelCase(s string) string

func LowerSnakeCase

func LowerSnakeCase(s string) string

func Register

func Register(g Generator)

func Snippet

func Snippet(format string, args ...Args) func(s SnippetWriter)

func UpperCamelCase

func UpperCamelCase(s string) string

func UpperSnakeCase

func UpperSnakeCase(s string) string

Types

type Args

type Args = map[string]interface{}

type Context

type Context struct {
	PkgPaths map[string]bool
	Args     *GeneratorArgs
	Universe gengotypes.Universe
	Package  gengotypes.Package
	Tags     map[string][]string
}

func NewContext

func NewContext(args *GeneratorArgs) (*Context, error)

func (*Context) Execute

func (c *Context) Execute(ctx context.Context, generators ...Generator) error

type Dumper

type Dumper struct {
	// contains filtered or unexported fields
}

func NewDumper

func NewDumper(rawNamer namer.Namer) *Dumper

func (*Dumper) Name

func (d *Dumper) Name(named gengotypes.TypeName) string

func (*Dumper) ReflectTypeLit

func (d *Dumper) ReflectTypeLit(tpe reflect.Type) string

func (*Dumper) TypeLit

func (d *Dumper) TypeLit(tpe typesutil.Type) string

func (*Dumper) TypesTypeLit

func (d *Dumper) TypesTypeLit(tpe types.Type) string

func (*Dumper) ValueLit

func (d *Dumper) ValueLit(in interface{}, optFns ...ValueLitOptFn) string

type Generator

type Generator interface {
	// Name generator name
	Name() string
	// New generator
	New() Generator
	// Init generator
	Init(*Context, GeneratorCreator) (Generator, error)
	// GenerateType do generate for each named type
	GenerateType(*Context, *types.Named) error
}

func GetRegisteredGenerators

func GetRegisteredGenerators(names ...string) (generators []Generator)

type GeneratorArgs

type GeneratorArgs struct {
	// Entrypoint should be import path or valid related dir path
	Entrypoint []string
	// OutputFileBaseName is the prefix of generated filename
	OutputFileBaseName string
}

type GeneratorCreator

type GeneratorCreator interface {
	Init(*Context, Generator, ...GeneratorPostInit) (Generator, error)
}

type GeneratorPostInit

type GeneratorPostInit = func(g Generator, sw SnippetWriter) error

type SnippetWriter

type SnippetWriter interface {
	io.Writer
	Do(format string, args ...Args)
	Dumper() *Dumper
}

func NewSnippetWriter

func NewSnippetWriter(w io.Writer, ns namer.NameSystems) SnippetWriter

type ValueLitOpt

type ValueLitOpt struct {
	SubValue    bool
	OnInterface func(v interface{}) string
	OnNamedType func(v interface{}) (string, bool)
}

type ValueLitOptFn

type ValueLitOptFn func(o *ValueLitOpt)

func OnInterface

func OnInterface(onUnknown func(v interface{}) string) ValueLitOptFn

func OnNamedType

func OnNamedType(onNamedType func(v interface{}) (string, bool)) ValueLitOptFn

func SubValue

func SubValue(sub bool) ValueLitOptFn

Jump to

Keyboard shortcuts

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