core

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// run mode list
	InSerialMode runMode = iota
	InConcurrentMode
	InSerialDebugMode
	InConcurrentDebugMode

	// generator Names
	GeneratorGin        = "gin"
	GeneratorChi        = "chi"
	GeneratorMux        = "mux"
	GeneratorEcho       = "echo"
	GeneratorIris       = "iris"
	GeneratorFiber      = "fiber"
	GeneratorFiberV2    = "fiberV2"
	GeneratorMacaron    = "macaron"
	GeneratorHttpRouter = "httprouter"

	// parser Names
	ParserStructTag = "structTag"
)

Variables

This section is empty.

Functions

func Logus added in v2.1.0

func Logus(format string, v ...interface{})

Logus print log info

func RegisterGenerators

func RegisterGenerators(gs ...Generator)

RegisterGenerators register generators

func RegisterParsers

func RegisterParsers(ps ...Parser)

RegisterParsers register parsers

Types

type Descriptors

type Descriptors map[string]IfaceDescriptors

Descriptors mir's Descriptor map {group: IfaceDescriptors}

func (Descriptors) Exist

func (d Descriptors) Exist(iface *IfaceDescriptor) bool

Exist whether exist *IfaceDescriptor sub-item

func (Descriptors) Get

func (d Descriptors) Get(group string) (IfaceDescriptors, bool)

Get get a IfaceDescriptors if exists

func (Descriptors) GroupFrom

func (d Descriptors) GroupFrom(key string) string

GroupFrom return group name from key

func (Descriptors) Put

func (d Descriptors) Put(iface *IfaceDescriptor) error

Put add a IfaceDescriptor Notice: if exist same instance by TypeName will override the old one

type EngineInfo added in v2.5.0

type EngineInfo struct {
	PkgName     string
	ImportAlias string // import alias name
}

EngineInfo Engine information

type FieldDescriptor

type FieldDescriptor struct {
	Host       string
	Path       string
	Queries    []string
	HttpMethod string
	MethodName string
	Comment    string // not support now so always empty
}

FieldDescriptor field Descriptor info

func (*FieldDescriptor) AnyHttpMethods added in v2.8.0

func (f *FieldDescriptor) AnyHttpMethods() []string

AnyHttpMethods return methods in HttpMethods Note this is assumed HttpMethods like ANY:POST,GET,HEAD

func (*FieldDescriptor) HttpMethodArgs added in v2.8.0

func (f *FieldDescriptor) HttpMethodArgs() string

HttpMethodArgs return http method as argument like "POST","GET","HEAD" Note this is assumed HttpMethods like ANY:POST,GET,HEAD

func (*FieldDescriptor) JustHttpAny added in v2.8.0

func (f *FieldDescriptor) JustHttpAny() bool

JustHttpAny not just http any method

func (*FieldDescriptor) NotHttpAny added in v2.8.0

func (f *FieldDescriptor) NotHttpAny() bool

NotHttpAny not just http any method

type Generator

type Generator interface {
	Name() string
	Init(opts *GeneratorOpts) error
	Generate(Descriptors) error
	GenerateContext(ctx MirCtx)
	Clone() Generator
}

Generator generate interface code for engine

func DefaultGenerator

func DefaultGenerator() Generator

DefaultGenerator get a default generator

func GeneratorByName

func GeneratorByName(name string) Generator

GeneratorByName get a generator by name

type GeneratorOpts added in v2.3.0

type GeneratorOpts struct {
	SinkPath string
	Cleanup  bool
}

GeneratorOpts used for initial generator

type IfaceDescriptor

type IfaceDescriptor struct {
	Group      string
	Chain      string
	PkgName    string
	TypeName   string
	Comment    string // not support now so always empty
	Fields     []*FieldDescriptor
	EngineInfo *EngineInfo
}

IfaceDescriptor interface Descriptor info

func (*IfaceDescriptor) SetPkgName

func (d *IfaceDescriptor) SetPkgName(name string)

SetPkgName set package name

type IfaceDescriptors

type IfaceDescriptors map[string]*IfaceDescriptor

IfaceDescriptors interface Descriptor map {TypeName:*IfaceDescriptor}

type InitOpts

type InitOpts struct {
	RunMode           runMode
	GeneratorName     string
	ParserName        string
	SinkPath          string
	DefaultTag        string
	EnginePkgName     string
	EngineImportAlias string
	NoneQuery         bool
	Cleanup           bool
}

InitOpts use for generator or parser init

func InitFrom added in v2.3.1

func InitFrom(opts Options) *InitOpts

InitFrom initial from Options and return an InitOpts instance

func (*InitOpts) GeneratorOpts added in v2.3.0

func (opts *InitOpts) GeneratorOpts() *GeneratorOpts

GeneratorOpts return a GeneratorOpts

func (*InitOpts) ParserOpts added in v2.3.0

func (opts *InitOpts) ParserOpts() *ParserOpts

ParserOpts return a ParserOpts instance

type MirCtx added in v2.1.0

type MirCtx interface {
	context.Context
	Cancel(err error)
	ParserDone()
	GeneratorDone()
	Wait() error
	Capcity() int
	Pipe() (<-chan *IfaceDescriptor, chan<- *IfaceDescriptor)
}

MirCtx mir's concurrent parser/generator context

type Option added in v2.3.0

type Option interface {
	// contains filtered or unexported methods
}

Option pass option to custom run behavior

func Cleanup added in v2.3.1

func Cleanup(enable bool) Option

Cleanup set generator cleanup out first when re-generate code

func DefaultTag added in v2.3.0

func DefaultTag(tag string) Option

DefaultTag set parser's default struct field tag string key

func EngineImportAlias added in v2.5.0

func EngineImportAlias(name string) Option

EngineImportAlias import package alias name

func EnginePkgName added in v2.5.0

func EnginePkgName(pkgName string) Option

EnginePkgName engine package name

func GeneratorName added in v2.3.0

func GeneratorName(name string) Option

GeneratorName set generator name option

func NoneQuery added in v2.4.0

func NoneQuery(enable bool) Option

NoneQuery set parser whether parse query

func ParserName added in v2.3.0

func ParserName(name string) Option

ParserName set parser name option

func RunMode added in v2.1.0

func RunMode(mode runMode) Option

RunMode set run mode option

func SinkPath added in v2.3.0

func SinkPath(path string) Option

SinkPath set generated code out directory

type Options

type Options []Option

Options generator options

func (Options) InitOpts added in v2.3.0

func (opts Options) InitOpts() *InitOpts

InitOpts return an initOpts instance

type Parser

type Parser interface {
	Name() string
	Init(opts *ParserOpts) error
	Parse(entries []interface{}) (Descriptors, error)
	ParseContext(ctx MirCtx, entries []interface{})
	Clone() Parser
}

Parser parse entries

func DefaultParser

func DefaultParser() Parser

DefaultParser get a default parser

func ParserByName

func ParserByName(name string) Parser

ParserByName get a parser by name

type ParserOpts added in v2.3.0

type ParserOpts struct {
	EngineInfo *EngineInfo
	DefaultTag string
	NoneQuery  bool
}

ParserOpts used for initial parser

Jump to

Keyboard shortcuts

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