generator

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package generator .

Index

Constants

View Source
const (
	KitexGenPath    = "kitex_gen"
	KitexImportPath = "github.com/cloudwego/kitex"
	DefaultCodec    = "thrift"

	BuildFileName     = "build.sh"
	BootstrapFileName = "bootstrap.sh"
	HandlerFileName   = "handler.go"
	MainFileName      = "main.go"
	ClientFileName    = "client.go"
	ServerFileName    = "server.go"
	InvokerFileName   = "invoker.go"
	ServiceFileName   = "*service.go"
)

Constants .

Variables

This section is empty.

Functions

func AddGlobalDependency

func AddGlobalDependency(ref, path string) bool

AddGlobalDependency adds dependency for all generators

func AddGlobalMiddleware

func AddGlobalMiddleware(mw Middleware)

AddGlobalMiddleware adds middleware for all generators

func HasFeature

func HasFeature(list []feature, key string) bool

HasFeature check whether a feature in the list

func RegisterFeature

func RegisterFeature(key string)

RegisterFeature register a feature

Types

type Config

type Config struct {
	Verbose         bool
	GenerateMain    bool // whether stuff in the main package should be generated
	GenerateInvoker bool // generate main.go with invoker when main package generate
	Version         string
	NoFastAPI       bool
	ModuleName      string
	ServiceName     string
	Use             string
	IDLType         string
	Includes        util.StringSlice
	ThriftOptions   util.StringSlice
	ProtobufOptions util.StringSlice
	IDL             string // the IDL file passed on the command line
	OutputPath      string // the output path for main pkg and kitex_gen
	PackagePrefix   string
	CombineService  bool // combine services to one service
	CopyIDL         bool
	ThriftPlugins   util.StringSlice
	Features        []feature
}

Config .

func (*Config) AddFeature

func (c *Config) AddFeature(key string) bool

AddFeature add registered feature to config

func (*Config) Pack

func (c *Config) Pack() (res []string)

Pack packs the Config into a slice of "key=val" strings.

func (*Config) Unpack

func (c *Config) Unpack(args []string) error

Unpack restores the Config from a slice of "key=val" strings.

type File

type File struct {
	Name    string
	Content string
}

File .

type Generator

type Generator interface {
	GenerateService(pkg *PackageInfo) ([]*File, error)
	GenerateMainPackage(pkg *PackageInfo) ([]*File, error)
}

Generator generates the codes of main package and scripts for building a server based on kitex.

func NewGenerator

func NewGenerator(config *Config, middlewares []Middleware) Generator

NewGenerator .

type HandleFunc

type HandleFunc func(*Task, *PackageInfo) (*File, error)

HandleFunc used generator

type MethodInfo

type MethodInfo struct {
	PkgInfo
	ServiceName            string
	Name                   string
	RawName                string
	Oneway                 bool
	Void                   bool
	Args                   []*Parameter
	Resp                   *Parameter
	Exceptions             []*Parameter
	ArgStructName          string
	ResStructName          string
	IsResponseNeedRedirect bool // int -> int*
	GenArgResultStruct     bool
	ClientStreaming        bool
	ServerStreaming        bool
}

MethodInfo .

type Middleware

type Middleware func(HandleFunc) HandleFunc

Middleware used generator

type PackageInfo

type PackageInfo struct {
	Namespace    string            // a dot-separated string for generating service package under kitex_gen
	Dependencies map[string]string // package name => import path, used for searching imports
	*ServiceInfo                   // the target service

	// the following fields will be filled and used by the generator
	Codec            string
	Version          string
	RealServiceName  string
	Imports          map[string]string // import path => alias
	ExternalKitexGen string
	Features         []feature
}

PackageInfo contains information to generate a package for a service.

func (*PackageInfo) AddImport

func (p *PackageInfo) AddImport(pkg, path string)

AddImport .

func (*PackageInfo) AddImports

func (p *PackageInfo) AddImports(pkgs ...string)

AddImports .

type Parameter

type Parameter struct {
	Deps    []PkgInfo
	Name    string
	RawName string
	Type    string // *PkgA.StructB
}

Parameter .

type PkgInfo

type PkgInfo struct {
	PkgName    string
	PkgRefName string
	ImportPath string
}

PkgInfo .

type ServiceInfo

type ServiceInfo struct {
	PkgInfo
	ServiceName     string
	RawServiceName  string
	ServiceTypeName func() string
	Base            *ServiceInfo
	Methods         []*MethodInfo
	CombineServices []*ServiceInfo
	HasStreaming    bool
}

ServiceInfo .

func (*ServiceInfo) AllMethods

func (s *ServiceInfo) AllMethods() (ms []*MethodInfo)

AllMethods returns all methods that the service have.

type Task

type Task struct {
	Name string
	Path string
	Text string
	*template.Template
}

Task .

func (*Task) Build

func (t *Task) Build() error

Build .

func (*Task) Render

func (t *Task) Render(data interface{}) (*File, error)

Render .

Jump to

Keyboard shortcuts

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