gengo

package
v0.0.0-...-30a8ca0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 28 Imported by: 7

Documentation

Index

Constants

View Source
const T = "__T__"

Variables

View Source
var (
	ErrSkip   = errors.New("skip")
	ErrIgnore = errors.New("ignore")
)
View Source
var (
	UpperSnakeCase = camelcase.UpperSnakeCase
	LowerSnakeCase = camelcase.LowerSnakeCase
	UpperKebabCase = camelcase.UpperKebabCase
	LowerKebabCase = camelcase.LowerKebabCase
	UpperCamelCase = camelcase.UpperCamelCase
	LowerCamelCase = camelcase.LowerCamelCase
)

Functions

func ImportGoPath

func ImportGoPath(importPath string) string

func IsGeneratorEnabled

func IsGeneratorEnabled(g Generator, tags map[string][]string) bool

func PkgImportPathAndExpose

func PkgImportPathAndExpose(s string) (string, string)

func Register

func Register(g Generator)

Types

type Context

type Context interface {
	LocateInPackage(pos token.Pos) gengotypes.Package
	Package(importPath string) gengotypes.Package
	Doc(typ types.Object) (Tags, []string)
	Render(snippet Snippet)
	Logger() logr.Logger
}

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 any, optFns ...ValueLitOptFn) string

type Executor

type Executor interface {
	Execute(ctx corecontext.Context, generators ...Generator) error
}

func NewContext

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

type Generator

type Generator interface {
	// Name generator name
	Name() string
	// 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
	// Globals contains tags for all pkgs
	Globals map[string][]string
}

type GeneratorCreator

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

type GeneratorNewer

type GeneratorNewer interface {
	// New generator
	New(c Context) Generator
}

type GeneratorPostInit

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

type Name

type Name = func(d *Dumper) string

func ID

func ID(v any) Name

type Render

type Render = func(sw SnippetWriter)

func Comment

func Comment(v string) Render

type Snippet

type Snippet map[string]any

func EachSnippet

func EachSnippet(n int, build func(i int) Snippet) []Snippet

func MapSnippet

func MapSnippet[T any](list []T, build func(item T) Snippet) []Snippet

func SnippetT

func SnippetT(t string) Snippet

type SnippetBuild

type SnippetBuild = func() Snippet

type SnippetWriter

type SnippetWriter interface {
	io.Writer
	Render(snippet Snippet)
}

func NewSnippetWriter

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

type Tags

type Tags map[string][]string

type ValueLitOpt

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

type ValueLitOptFn

type ValueLitOptFn func(o *ValueLitOpt)

func OnInterface

func OnInterface(onUnknown func(v any) string) ValueLitOptFn

func OnNamedType

func OnNamedType(onNamedType func(v any) (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