generator

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "v0.8.2"

Variables

View Source
var (
	ErrServiceNotFound     = errors.New("service not found")
	ErrEmptyService        = errors.New("empty service")
	ErrNotInterface        = errors.New("service is not an interface")
	ErrNoCtxParam          = errors.New(`first param is not "context.Context"`)
	ErrInvalidResults      = errors.New(`method results are not "error", neither "(SomeType, error)"`)
	ErrInvalidGenerateType = errors.New("invalid generate type")
)
View Source
var (
	ErrEventNotFound    = errors.New("event not found")
	ErrEventDocNotFound = errors.New("event doc not found")
)

Functions

func GenImports added in v0.2.0

func GenImports(data GenImportsData) (string, error)

func GenPackage added in v0.2.0

func GenPackage(data GenPackageData) (string, error)

func GeneratePublishEvents added in v0.2.0

func GeneratePublishEvents(o PublishEventsOptions) (string, error)

func LoadSource added in v0.2.0

func LoadSource(pkg string) (*packages.Package, error)

Types

type Event added in v0.2.0

type Event struct {
	Name  string
	Topic string
}

type GenImportsData added in v0.2.0

type GenImportsData struct {
	Imports map[ImportPkg]ImportAlias
}

type GenPackageData added in v0.2.0

type GenPackageData struct {
	PackageName string
	GenComment  bool
	Version     string
	SourceType  string
}

type GenerateType added in v0.2.0

type GenerateType string
const (
	GenerateTypeService    GenerateType = "service"
	GenerateTypeSubscriber GenerateType = "subscriber"
)

func GenerateTypeFromString added in v0.2.0

func GenerateTypeFromString(t string) (GenerateType, error)

type Generator

type Generator struct {
	Version    string
	SourceType string
	Package    *packages.Package

	GenerateType GenerateType

	ServicePkg  string
	ServiceType string

	PackageName string // package {{.PackageName}}
	GenComment  bool
	Imports     map[string]string // package->alias
	Methods     []*Method
}

func NewGenerator

func NewGenerator(o Options) *Generator

func (*Generator) AddImport

func (g *Generator) AddImport(pkg, alias string)

func (*Generator) Build

func (g *Generator) Build() error

func (*Generator) BuildMethod

func (g *Generator) BuildMethod(m *types.Func) error

func (*Generator) Generate

func (g *Generator) Generate() (string, error)

type Id

type Id struct {
	Pkg  string
	Name string
}

type ImportAlias added in v0.2.0

type ImportAlias = string

type ImportPkg added in v0.2.0

type ImportPkg = string

type Method

type Method struct {
	Name         string
	Params       []*Param
	Responses    []*Response
	Response     *Response
	Variadic     bool
	VariadicType string
}

type Options

type Options struct {
	ServicePkg   string
	ServiceType  string
	GenComment   bool
	GenerateType GenerateType
}

type Param

type Param struct {
	Name    string
	Type    string
	SigType string
}

type PublishEventsOptions added in v0.2.0

type PublishEventsOptions struct {
	Pkg        string
	GenComment bool
}

type Response

type Response struct {
	Name string
	Type string
	Ptr  bool
}

type Subscriber added in v0.2.3

type Subscriber struct {
	EventName   string
	HandlerName string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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