kid

package module
v0.5.42 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 25 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 = NewValidator()

Functions

func NewValidator

func NewValidator() *validator.Validate
func PrintLogo()

func Struct

func Struct(value interface{}) error

func Verify

func Verify(ctx *Context, rules Rules) error

Types

type Context

type Context struct {
	*gin.Context
}

func (*Context) BindUser

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

BindUser 绑定用户

func (*Context) FindBool

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

func (*Context) FindDefaultBool

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

func (*Context) FindDefaultFloat32

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

func (*Context) FindDefaultFloat64

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

func (*Context) FindDefaultInt

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

func (*Context) FindDefaultInt64

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

func (*Context) FindDefaultInt8

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

func (*Context) FindDefaultString

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

func (*Context) FindDefaultUint8

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

func (*Context) FindFloat32

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

func (*Context) FindFloat64

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

func (*Context) FindInt

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

func (*Context) FindInt64

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

func (*Context) FindInt8

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

func (*Context) FindString

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

func (*Context) FindUint8

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

func (*Context) GetBindUser

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

GetBindUser 获取绑定的用户

func (*Context) GetResponseType

func (ctx *Context) GetResponseType() ResponseType

GetResponseType 获取响应格式化类型

func (*Context) GetValue

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

func (*Context) SetResponseType

func (ctx *Context) SetResponseType(respType ResponseType)

SetResponseType 指定响应格式类型

func (*Context) Valid

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

func (*Context) ValidFiled

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

type HandleFunc

type HandleFunc func(*Context) any

func WrapHandler

func WrapHandler(handler gin.HandlerFunc) HandleFunc

type Kid

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

func New

func New(opts ...Option) *Kid

func Registry

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

func (*Kid) AutoMigrate

func (kid *Kid) AutoMigrate(closeFKCheck bool)

AutoMigrate 自动迁移数据库

func (*Kid) CommandLine

func (kid *Kid) CommandLine() error

CommandLine 命令行处理

func (*Kid) Init

func (kid *Kid) Init() error

func (*Kid) Launch

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

func (*Kid) NewDbCommand

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

NewDbCommand 数据库相关命令

func (*Kid) NewHelpCommand

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

func (*Kid) NewServerCommand

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

NewServerCommand 服务启动相关命令

func (*Kid) NoMethod

func (kid *Kid) NoMethod(handleFunc HandleFunc)

func (*Kid) NoRoute

func (kid *Kid) NoRoute(handleFunc HandleFunc)

func (*Kid) Populate

func (kid *Kid) Populate() error

func (*Kid) Registry

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

Registry 将插件注入容器

type LogFormatter

type LogFormatter func(params LogFormatterParams) string

type LogFormatterParams

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

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

type Middleware

type Middleware func(*Context)

func LoggerWithConfig

func LoggerWithConfig(conf LoggerConfig) Middleware

func LoggerWithFormatter

func LoggerWithFormatter(f LogFormatter) Middleware

type Option

type Option func(*Options)

func WithAppName

func WithAppName(name string) Option

func WithConfigs

func WithConfigs(configs ...string) Option

func WithDbMigrate

func WithDbMigrate(migrate mysql.AutoMigrate) Option

func WithRunMode

func WithRunMode(runMode string) Option

type Options

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

type ResponseType

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

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

type Rules

type Rules map[string]interface{}

Jump to

Keyboard shortcuts

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