generator

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ServiceSuffix = "Service"

Variables

This section is empty.

Functions

func SetDefaultTemplateConfig

func SetDefaultTemplateConfig()

Types

type ClientConfig

type ClientConfig struct {
	QueryEnumAsInt bool
}

type ClientFile

type ClientFile struct {
	Config        ClientConfig
	FilePath      string
	PackageName   string
	ServiceName   string
	BaseDomain    string
	Imports       map[string]*model.Model
	ClientMethods []*ClientMethod
}

type ClientGenerator

type ClientGenerator interface {
}

type ClientMethod

type ClientMethod struct {
	*HttpMethod
	BodyParamsCode   string
	QueryParamsCode  string
	PathParamsCode   string
	HeaderParamsCode string
	FormValueCode    string
	FormFileCode     string
	DecodeCustomKey  string
}

type CustomizedFileForIDL

type CustomizedFileForIDL struct {
	*IDLPackageRenderInfo
	FilePath    string
	FilePackage string
}

type CustomizedFileForMethod

type CustomizedFileForMethod struct {
	*HttpMethod
	FilePath       string
	FilePackage    string
	ServiceInfo    *Service              // service info for this method
	IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service
}

type CustomizedFileForService

type CustomizedFileForService struct {
	*Service
	FilePath       string
	FilePackage    string
	IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service
}

type ErrorFile

type ErrorFile struct {
}

type FilePathRenderInfo

type FilePathRenderInfo struct {
	MasterIDLName  string // master IDL name
	GenPackage     string // master IDL generate code package
	HandlerDir     string // handler generate dir
	ModelDir       string // model generate dir
	RouterDir      string // router generate dir
	ProjectDir     string // projectDir
	GoModule       string // go module
	ServiceName    string // service name, changed as services are traversed
	MethodName     string // method name, changed as methods are traversed
	HandlerGenPath string // "api.gen_path" value
}

type Generator

type Generator interface {
	Generate(serviceName string)
	GenerateDocs(serviceName string)
}

type HttpMethod

type HttpMethod struct {
	Name               string
	HTTPMethod         string
	Comment            string
	Path               string
	Serializer         string
	OutputDir          string
	RefPackage         string // handler import dir
	RefPackageAlias    string // handler import alias
	RequestTypeName    string
	RequestTypePackage string
	RequestTypeRawName string
	ReturnTypeName     string
	ReturnTypePackage  string
	ReturnTypeRawName  string
	ModelPackage       map[string]string
	GenHandler         bool // Whether to generate one handler, when an idl interface corresponds to multiple http method
	// Annotations     map[string]string
	Models map[string]*model.Model
}

type HttpPackageGenerator

type HttpPackageGenerator struct {
	ServiceGroup string

	ConfigPath     string // package template path
	CmdType        string
	Backend        meta.Backend // model template
	Options        []Option
	ProjPackage    string // go module for project
	ModelDir       string
	UseDir         string // model dir for third repo
	ClientDir      string // client dir for "new"/"update" command
	IdlClientDir   string // client dir for "client" command
	ForceClientDir string // client dir without namespace for "client" command
	BaseDomain     string // request domain for "client" command
	QueryEnumAsInt bool   // client code use number for query parameter
	ServiceGenDir  string

	NeedModel            bool
	SnakeStyleMiddleware bool // use snake name style for middleware
	ForceUpdateClient    bool // force update 'crafter_client.go'

	tpl.TemplateGenerator
	// contains filtered or unexported fields
}

HttpPackageGenerator is used to record the configuration related to generating crafter http code.

func (*HttpPackageGenerator) GenModel

func (pkgGen *HttpPackageGenerator) GenModel(data *model.Model, gen bool) error

func (*HttpPackageGenerator) GeneratePackage

func (pkgGen *HttpPackageGenerator) GeneratePackage(pkg *PackageDescription) error

func (*HttpPackageGenerator) Init

func (pkgGen *HttpPackageGenerator) Init() error

func (*HttpPackageGenerator) LoadBackend

func (pkgGen *HttpPackageGenerator) LoadBackend(backend meta.Backend) error

type IDLPackageRenderInfo

type IDLPackageRenderInfo struct {
	FilePathRenderInfo
	ServiceInfos *PackageDescription
}

type Layout

type Layout struct {
	OutDir      string
	GoModule    string
	ServiceName string
	HasIdl      bool
	NeedGoMod   bool
	ModelDir    string
	HandlerDir  string
	RouterDir   string
}

Layout contains the basic information of idl

type LayoutGenerator

type LayoutGenerator struct {
	ConfigPath string
	tpl.TemplateGenerator
}

LayoutGenerator contains the information generated by generating the layout template

func (*LayoutGenerator) Degenerate

func (lg *LayoutGenerator) Degenerate() error

func (*LayoutGenerator) Generate

func (lg *LayoutGenerator) Generate(data map[string]interface{}) error

func (*LayoutGenerator) GenerateByConfig

func (lg *LayoutGenerator) GenerateByConfig(configPath string) error

func (*LayoutGenerator) GenerateByService

func (lg *LayoutGenerator) GenerateByService(service Layout) error

func (*LayoutGenerator) Init

func (lg *LayoutGenerator) Init() error

type ModelBackend

type ModelBackend interface {
	Template() (*template.Template, error)
	Element() map[string]string
	SetOption(opts string) error
	GetOptions() []string
	RegisterFuncs(name string, fn interface{}) error
}

type Option

type Option string
const (
	OptionMarshalEnumToText  Option = "MarshalEnumToText"
	OptionTypedefAsTypeAlias Option = "TypedefAsTypeAlias"
)

type PackageDescription

type PackageDescription struct {
	IdlName  string
	Package  string
	Services []*Service
	Models   []*model.Model
}

type Service

type Service struct {
	Name             string
	Version          string
	Methods          []*HttpMethod
	ClientMethods    []*ClientMethod
	DependencyModels []*model.Model
	ServiceGroup     string
	ServiceGenDir    string
	BaseDomain       string // base domain for client code
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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