Documentation
¶
Index ¶
- Constants
- Variables
- func Logus(format string, v ...any)
- func RegisterGenerators(gs ...Generator)
- func RegisterParsers(ps ...Parser)
- type Descriptors
- type EngineInfo
- type FieldDescriptor
- func (f *FieldDescriptor) AnyHttpMethods() []string
- func (f *FieldDescriptor) HttpMethod() string
- func (f *FieldDescriptor) HttpMethodArgs() string
- func (f *FieldDescriptor) InName() string
- func (f *FieldDescriptor) JustHttpAny() bool
- func (f *FieldDescriptor) NotHttpAny() bool
- func (f *FieldDescriptor) OrInOut() bool
- func (f *FieldDescriptor) OutName() string
- type Generator
- type GeneratorOpts
- type IfaceDescriptor
- func (d *IfaceDescriptor) AllInOuts() []reflect.Type
- func (d *IfaceDescriptor) BindingFields() (fields []*FieldDescriptor)
- func (d *IfaceDescriptor) ChainFields() (fields []*FieldDescriptor)
- func (d *IfaceDescriptor) IsUseBinding() bool
- func (d *IfaceDescriptor) IsUseFieldChain() bool
- func (d *IfaceDescriptor) SetDeclareCoreInterface(isNeed bool)
- func (d *IfaceDescriptor) SetInnerInOuts(inOuts []reflect.Type)
- func (d *IfaceDescriptor) SetPkgName(name string)
- type IfaceDescriptors
- type InitOpts
- type MirCtx
- type Option
- func AssertType[T any]() Option
- func AssertType2[B, R any]() Option
- func Cleanup(enable bool) Option
- func DefaultTag(tag string) Option
- func EngineImportAlias(name string) Option
- func EnginePkgName(pkgName string) Option
- func GeneratorName(name string) Option
- func NoneQuery(enable bool) Option
- func ParserName(name string) Option
- func RunMode(mode runMode) Option
- func SinkPath(path string) Option
- func WatchCtxDone(enable bool) Option
- type Options
- type Parser
- type ParserOpts
- type VersionInfo
Constants ¶
const ( // run mode list InSerialMode runMode = iota InConcurrentMode InSerialDebugMode InConcurrentDebugMode // generator Names GeneratorGin = "gin" GeneratorChi = "chi" GeneratorMux = "mux" GeneratorHertz = "hertz" GeneratorEcho = "echo" GeneratorIris = "iris" GeneratorFiber = "fiber" GeneratorMacaron = "macaron" GeneratorHttpRouter = "httprouter" // parser Names ParserStructTag = "structTag" )
Variables ¶
var (
VerInfo = &VersionInfo{
MirVer: "v4.0.0",
}
)
Functions ¶
func RegisterGenerators ¶
func RegisterGenerators(gs ...Generator)
RegisterGenerators register generators
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 ¶
EngineInfo Engine information
type FieldDescriptor ¶
type FieldDescriptor struct { Imports map[string]string PkgPath string Host string Path string Queries []string HttpMethods []string IsAnyMethod bool IsFieldChain bool IsBindIn bool IsRenderOut bool In reflect.Type Out reflect.Type InOuts []reflect.Type MethodName string Comment string // not support now so always empty }
FieldDescriptor field Descriptor info
func (*FieldDescriptor) AnyHttpMethods ¶
func (f *FieldDescriptor) AnyHttpMethods() []string
AnyHttpMethods return methods in HttpMethods
func (*FieldDescriptor) HttpMethod ¶
func (f *FieldDescriptor) HttpMethod() string
HttpMethod return http method when f.NotHttpAny() is true
func (*FieldDescriptor) HttpMethodArgs ¶
func (f *FieldDescriptor) HttpMethodArgs() string
HttpMethodArgs return http method as argument like "POST","GET","HEAD"
func (*FieldDescriptor) InName ¶
func (f *FieldDescriptor) InName() string
InName return In type name
func (*FieldDescriptor) JustHttpAny ¶
func (f *FieldDescriptor) JustHttpAny() bool
JustHttpAny just http any method
func (*FieldDescriptor) NotHttpAny ¶
func (f *FieldDescriptor) NotHttpAny() bool
NotHttpAny not just http any method
func (*FieldDescriptor) OutName ¶
func (f *FieldDescriptor) OutName() string
OutName return Out type name
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 GeneratorByName ¶
GeneratorByName get a generator by name
type GeneratorOpts ¶
GeneratorOpts used for initial generator
type IfaceDescriptor ¶
type IfaceDescriptor struct { Group string Chain string Imports map[string]string PkgPath string PkgName string TypeName string Comment string // not support now so always empty InOuts []reflect.Type Fields []*FieldDescriptor EngineInfo *EngineInfo VerInfo *VersionInfo WatchCtxDone bool DeclareCoreInterface bool // whether need to declare core interface, default is false }
IfaceDescriptor interface Descriptor info
func (*IfaceDescriptor) AllInOuts ¶
func (d *IfaceDescriptor) AllInOuts() []reflect.Type
AllInOuts return all InOuts from Fileds
func (*IfaceDescriptor) BindingFields ¶
func (d *IfaceDescriptor) BindingFields() (fields []*FieldDescriptor)
BindingFields return Binding's fields
func (*IfaceDescriptor) ChainFields ¶
func (d *IfaceDescriptor) ChainFields() (fields []*FieldDescriptor)
ChainFields return field chains
func (*IfaceDescriptor) IsUseBinding ¶
func (d *IfaceDescriptor) IsUseBinding() bool
IsUseBinding return whether use binding interface
func (*IfaceDescriptor) IsUseFieldChain ¶
func (d *IfaceDescriptor) IsUseFieldChain() bool
IsUseFieldChain whether use field chain
func (*IfaceDescriptor) SetDeclareCoreInterface ¶
func (d *IfaceDescriptor) SetDeclareCoreInterface(isNeed bool)
SetDeclareCoreInterface set declare core interface value
func (*IfaceDescriptor) SetInnerInOuts ¶
func (d *IfaceDescriptor) SetInnerInOuts(inOuts []reflect.Type)
SetInnerInOuts set inner InOuts for defined
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}
func (IfaceDescriptors) SortedIfaces ¶
func (d IfaceDescriptors) SortedIfaces() []*IfaceDescriptor
SortedIfaces return sorted Iface slice
type InitOpts ¶
type InitOpts struct { RunMode runMode GeneratorName string ParserName string SinkPath string DefaultTag string EnginePkgName string EngineImportAlias string WatchCtxDone bool NoneQuery bool Cleanup bool }
InitOpts use for generator or parser init
func (*InitOpts) GeneratorOpts ¶
func (opts *InitOpts) GeneratorOpts() *GeneratorOpts
GeneratorOpts return a GeneratorOpts
func (*InitOpts) ParserOpts ¶
func (opts *InitOpts) ParserOpts() *ParserOpts
ParserOpts return a ParserOpts instance
type MirCtx ¶
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 ¶
type Option interface {
// contains filtered or unexported methods
}
Option pass option to custom run behavior
func AssertType ¶
AssertType[T] register assert.TypeAssertor for custom T type
func AssertType2 ¶
AssertType2[B, R] register assert.TypeAssertor for custom B(Binding) and R(Render) type
func DefaultTag ¶
DefaultTag set parser's default struct field tag string key
func EngineImportAlias ¶
EngineImportAlias import package alias name
func WatchCtxDone ¶
WatchCtxDone set generator whether watch context done when Register Servants in generated code. default watch context done.
type Parser ¶
type Parser interface { Name() string Init(opts *ParserOpts) error Parse(entries []any) (Descriptors, error) ParseContext(ctx MirCtx, entries []any) Clone() Parser }
Parser parse entries
type ParserOpts ¶
type ParserOpts struct { EngineInfo *EngineInfo DefaultTag string WatchCtxDone bool NoneQuery bool }
ParserOpts used for initial parser