core

package
v4.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	VerInfo = &VersionInfo{
		MirVer: "v4.0.0",
	}
)

Functions

func Logus

func Logus(format string, v ...any)

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

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

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) OrInOut

func (f *FieldDescriptor) OrInOut() bool

OrInOut in or out

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 DefaultGenerator

func DefaultGenerator() Generator

DefaultGenerator get a default generator

func GeneratorByName

func GeneratorByName(name string) Generator

GeneratorByName get a generator by name

type GeneratorOpts

type GeneratorOpts struct {
	SinkPath string
	Cleanup  bool
}

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 InitFrom

func InitFrom(opts Options) *InitOpts

InitFrom initial from Options and return an InitOpts instance

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

func AssertType[T any]() Option

AssertType[T] register assert.TypeAssertor for custom T type

func AssertType2

func AssertType2[B, R any]() Option

AssertType2[B, R] register assert.TypeAssertor for custom B(Binding) and R(Render) type

func Cleanup

func Cleanup(enable bool) Option

Cleanup set generator cleanup out first when re-generate code

func DefaultTag

func DefaultTag(tag string) Option

DefaultTag set parser's default struct field tag string key

func EngineImportAlias

func EngineImportAlias(name string) Option

EngineImportAlias import package alias name

func EnginePkgName

func EnginePkgName(pkgName string) Option

EnginePkgName engine package name

func GeneratorName

func GeneratorName(name string) Option

GeneratorName set generator name option

func NoneQuery

func NoneQuery(enable bool) Option

NoneQuery set parser whether parse query

func ParserName

func ParserName(name string) Option

ParserName set parser name option

func RunMode

func RunMode(mode runMode) Option

RunMode set run mode option

func SinkPath

func SinkPath(path string) Option

SinkPath set generated code out directory

func WatchCtxDone

func WatchCtxDone(enable bool) Option

WatchCtxDone set generator whether watch context done when Register Servants in generated code. default watch context done.

type Options

type Options []Option

Options generator options

func (Options) InitOpts

func (opts Options) InitOpts() *InitOpts

InitOpts return an initOpts instance

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

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

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

ParserOpts used for initial parser

type VersionInfo

type VersionInfo struct {
	MirVer string
}

VersionInfo mir version information

Jump to

Keyboard shortcuts

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