kid

package module
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 20 Imported by: 0

README

kid

Documentation

Index

Constants

View Source
const (
	ResponseTypeJson           = iota + 1 // 1 json 类型
	ResponseTypeXml                       // 2 xml 类型
	ResponseTypeYaml                      // 3 yaml 类型
	ResponseTypeHtml                      // 4 html 类型
	ResponseTypeIndentedJson              // 5 格式化 json
	ResponseTypeSecureJson                // 6 安全的 json
	ResponseTypeJsonP                     // 7 返回 jsonp 格式
	ResponseTypeAsciiJson                 // 8 返回 Ascii 码的 json 会将 Unicode 转换为 ASCII
	ResponseTypePureJson                  // 9 pure json 格式化
	ResponseTypeToml                      // 10 分会 toml 格式
	ResponseTypeProtoBuf                  // 11 以 protobuf 格式输出
	ResponseTypeString                    // 12 以字符串格式输出
	ResponseTypeRedirect                  // 13 重定向
	ResponseTypeFile                      // 14 文件
	ResponseTypeFileFromFS                // 15 远程文件系统
	ResponseTypeFileAttachment            // 16 FileAttachment
	ResponseTypeSSEvent                   // 17 SSEvent
	ResponseTypeStream                    // 18 数据流
)
View Source
View Source
const (
	ResponseTypeKey = "resp_type"
)
View Source
const UserBindKey = "bind_user"

Variables

View Source
var Validator = validator.New()

Functions

func PrintLogo()

func Struct added in v0.0.4

func Struct(value interface{}) error

func Verify added in v0.0.4

func Verify(ctx *Context, rules Rules) (err error)

Types

type Context

type Context struct {
	*gin.Context
}

func (*Context) BindUser added in v0.0.4

func (ctx *Context) BindUser(val interface{})

BindUser 绑定用户

func (*Context) FindBool added in v0.0.4

func (ctx *Context) FindBool(key string) bool

func (*Context) FindDefaultBool added in v0.0.4

func (ctx *Context) FindDefaultBool(key string, defaultValue bool) bool

func (*Context) FindDefaultFloat32 added in v0.0.4

func (ctx *Context) FindDefaultFloat32(key string, defaultValue float32) float32

func (*Context) FindDefaultFloat64 added in v0.0.4

func (ctx *Context) FindDefaultFloat64(key string, defaultValue float64) float64

func (*Context) FindDefaultInt added in v0.0.4

func (ctx *Context) FindDefaultInt(key string, defaultValue int) int

func (*Context) FindDefaultInt64 added in v0.0.4

func (ctx *Context) FindDefaultInt64(key string, defaultValue int64) int64

func (*Context) FindDefaultInt8 added in v0.0.4

func (ctx *Context) FindDefaultInt8(key string, defaultVal int8) int8

func (*Context) FindDefaultString added in v0.0.4

func (ctx *Context) FindDefaultString(key, defaultValue string) string

func (*Context) FindDefaultUint8 added in v0.0.4

func (ctx *Context) FindDefaultUint8(key string, defaultVal uint8) uint8

func (*Context) FindFloat32 added in v0.0.4

func (ctx *Context) FindFloat32(key string) float32

func (*Context) FindFloat64 added in v0.0.4

func (ctx *Context) FindFloat64(key string) float64

func (*Context) FindInt added in v0.0.4

func (ctx *Context) FindInt(key string) int

func (*Context) FindInt64 added in v0.0.4

func (ctx *Context) FindInt64(key string) int64

func (*Context) FindInt8 added in v0.0.4

func (ctx *Context) FindInt8(key string) int8

func (*Context) FindString added in v0.0.4

func (ctx *Context) FindString(key string) string

func (*Context) FindUint8 added in v0.0.4

func (ctx *Context) FindUint8(key string) uint8

func (*Context) GetBindUser added in v0.0.4

func (ctx *Context) GetBindUser(recipient interface{}) error

GetBindUser 获取绑定的用户

func (*Context) GetResponseType added in v0.0.4

func (ctx *Context) GetResponseType() ResponseType

GetResponseType 获取响应格式化类型

func (*Context) GetValue added in v0.0.4

func (ctx *Context) GetValue(key string, recipient interface{}) error

func (*Context) SetResponseType added in v0.0.4

func (ctx *Context) SetResponseType(respType ResponseType)

SetResponseType 指定响应格式类型

func (*Context) Valid added in v0.0.4

func (ctx *Context) Valid(recipient interface{}) error

func (*Context) ValidFiled added in v0.0.4

func (ctx *Context) ValidFiled(rules Rules) error

type HandleFunc

type HandleFunc func(*Context) interface{}

type Kid

type Kid struct {
	*gin.Engine
	RouterGroup
	Logger       logger.Logger
	IocContainer *container.Container
	Options      *Options
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Kid

func Registry added in v0.0.4

func Registry(plugin plugin.Plugin, opts ...container.Option) *Kid

func (*Kid) AutoMigrate added in v0.0.4

func (kid *Kid) AutoMigrate()

AutoMigrate 自动迁移数据库

func (*Kid) CommandLine added in v0.0.4

func (kid *Kid) CommandLine() error

CommandLine 命令行处理

func (*Kid) Get added in v0.0.4

func (kid *Kid) Get(plugin plugin.Plugin, name ...string) (interface{}, error)

func (*Kid) Init added in v0.0.4

func (kid *Kid) Init() error

func (*Kid) Launch

func (kid *Kid) Launch(hosts ...string)

func (*Kid) NewDbCommand added in v0.0.4

func (kid *Kid) NewDbCommand() *cobra.Command

NewDbCommand 数据库相关命令

func (*Kid) NewHelpCommand added in v0.0.4

func (kid *Kid) NewHelpCommand() *cobra.Command

func (*Kid) NewServerCommand added in v0.0.4

func (kid *Kid) NewServerCommand() *cobra.Command

NewServerCommand 服务启动相关命令

func (*Kid) NoMethod added in v0.0.4

func (kid *Kid) NoMethod(handleFunc HandleFunc)

func (*Kid) NoRoute added in v0.0.4

func (kid *Kid) NoRoute(handleFunc HandleFunc)

func (*Kid) Populate added in v0.0.4

func (kid *Kid) Populate() error

func (*Kid) PopulateOne added in v0.0.4

func (kid *Kid) PopulateOne(plugin plugin.Plugin, opts ...container.Option) error

func (*Kid) Registry

func (kid *Kid) Registry(plugin plugin.Plugin, opts ...container.Option) *Kid

Registry 将插件注入容器

type LogFormatter added in v0.0.4

type LogFormatter func(params LogFormatterParams) string

type LogFormatterParams added in v0.0.4

type LogFormatterParams struct {
	Request      *http.Request
	TimeStamp    time.Time
	StatusCode   int
	Latency      time.Duration
	ClientIP     string
	Method       string
	Path         string
	ErrorMessage string

	BodySize int
	Keys     map[string]interface{}
	// contains filtered or unexported fields
}

type LoggerConfig added in v0.0.4

type LoggerConfig struct {
	Formatter LogFormatter
	Output    io.Writer
	SkipPaths []string
}

type Middleware added in v0.0.4

type Middleware func(*Context)

func LoggerWithConfig added in v0.0.4

func LoggerWithConfig(conf LoggerConfig) Middleware

func LoggerWithFormatter added in v0.0.4

func LoggerWithFormatter(f LogFormatter) Middleware

type Option added in v0.0.4

type Option func(*Options)

func WithAppName added in v0.0.4

func WithAppName(name string) Option

func WithConfigs added in v0.0.4

func WithConfigs(configs ...string) Option

func WithDbMigrate added in v0.0.4

func WithDbMigrate(migrate mysql.AutoMigrate) Option

func WithRunMode added in v0.0.4

func WithRunMode(runMode string) Option

type Options added in v0.0.4

type Options struct {
	Name            string
	AutoMigrate     bool
	Configs         []string
	RunMode         string
	DatabaseMigrate mysql.AutoMigrate
}

type ResponseType added in v0.0.4

type ResponseType int8

type RouterGroup

type RouterGroup struct {
	*gin.RouterGroup
}

func (*RouterGroup) DELETE

func (group *RouterGroup) DELETE(path string, handler HandleFunc, middlewares ...Middleware)

func (*RouterGroup) GET

func (group *RouterGroup) GET(path string, handler HandleFunc, middlewares ...Middleware)

func (*RouterGroup) Group

func (group *RouterGroup) Group(path string, middlewares ...Middleware) *RouterGroup

func (*RouterGroup) POST

func (group *RouterGroup) POST(path string, handler HandleFunc, middlewares ...Middleware)

func (*RouterGroup) PUT

func (group *RouterGroup) PUT(path string, handler HandleFunc, middlewares ...Middleware)

func (*RouterGroup) UseMiddle added in v0.0.4

func (group *RouterGroup) UseMiddle(middlewares ...Middleware)

type Rules added in v0.0.4

type Rules map[string]interface{}

Jump to

Keyboard shortcuts

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