Documentation
¶
Index ¶
- Constants
- func DefaultHTTPErrorHandler(err error, c *Context)
- func SetLogLevel(level int)
- func SetLogger(l Logger)
- type Config
- type Context
- func (c *Context) Abort()
- func (c *Context) Cache() interface{}
- func (c *Context) ClientIP() string
- func (c *Context) Config() *config.ConfigManager
- func (c *Context) ConfigBool(key string, defaultValue bool) bool
- func (c *Context) ConfigInt(key string, defaultValue int) int
- func (c *Context) ConfigString(key string, defaultValue string) string
- func (c *Context) ConfigValue(key string) interface{}
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) DB() *gorm.DB
- func (c *Context) Error(err error) *gin.Error
- func (c *Context) Get(key string) (interface{}, bool)
- func (c *Context) GetHeader(key string) string
- func (c *Context) Header(key, value string)
- func (c *Context) Inject(function interface{}) error
- func (c *Context) IntParam(value string) (int, error)
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) Next()
- func (c *Context) ParamUint(key string) uint
- func (c *Context) Query(key string) string
- func (c *Context) QueryInt(key string, defaultValue int) int
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) Status(code int)
- func (c *Context) String(code int, format string, values ...interface{})
- func (c *Context) UintParam(value string) (uint, error)
- type Engine
- func (e *Engine) Container() *dig.Container
- func (e *Engine) DB() (*db.DbProvider, bool)
- func (e *Engine) DELETE(relativePath string, handlers ...HandlerFunc)
- func (e *Engine) DI() *di.Container
- func (e *Engine) GET(relativePath string, handlers ...HandlerFunc)
- func (e *Engine) GetConfig() *Config
- func (e *Engine) GetLogger() Logger
- func (e *Engine) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
- func (e *Engine) Handle(httpMethod, relativePath string, handlers ...HandlerFunc)
- func (e *Engine) Invoke(function interface{}) error
- func (e *Engine) IsDebug() bool
- func (e *Engine) NewContext(c *gin.Context) *Context
- func (e *Engine) OnShutdown(fn func(), priority ...int)
- func (e *Engine) OnStart(fn func(), priority ...int)
- func (e *Engine) PATCH(relativePath string, handlers ...HandlerFunc)
- func (e *Engine) POST(relativePath string, handlers ...HandlerFunc)
- func (e *Engine) PUT(relativePath string, handlers ...HandlerFunc)
- func (e *Engine) Provide(constructor interface{}) error
- func (e *Engine) RegisterModule(m Module) error
- func (e *Engine) RegisterModules(modules ...Module) error
- func (e *Engine) Run(addr ...string) error
- func (e *Engine) Shutdown(ctx context.Context) error
- func (e *Engine) Use(middleware ...HandlerFunc) *Engine
- func (e *Engine) WaitForTermination()
- func (e *Engine) WithDatabase(options ...interface{}) *Engine
- type H
- type HTTPError
- type HandlerFunc
- type Logger
- type Module
- type Option
- func WithConfig(configPath string) Option
- func WithConfigWatcher(callback func()) Option
- func WithDatabase(options ...interface{}) Option
- func WithLogLevel(level string) Option
- func WithLogger(l Logger) Option
- func WithMiddleware(middleware ...HandlerFunc) Option
- func WithMode(mode string) Option
- func WithServiceProvider(constructor interface{}) Option
- func WithStaticFiles(urlPath, dirPath string) Option
- func WithTemplates(pattern string) Option
- type RoutableModule
- type RouterGroup
- func (g *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) GET(relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) POST(relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc)
- func (g *RouterGroup) Use(middleware ...HandlerFunc) *RouterGroup
Constants ¶
const ( // 版本信息 Version = "3.0.1" FlowBanner = ` [%s] [INFO] ┌─┐┬ ┌─┐┬ ┬ ├┤ │ │ ││││ └ ┴─┘└─┘└┴┘ ` )
全局常量
const ( LogLevelDebug = iota LogLevelInfo LogLevelWarn LogLevelError )
日志级别常量
Variables ¶
This section is empty.
Functions ¶
func DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler 是默认的HTTP错误处理函数
Types ¶
type Config ¶
type Config struct {
Mode string // 运行模式: debug, release, test
JSONLib string // JSON库: default, gojson
LogLevel string // 日志级别: debug, info, warn, error
ConfigPath string // 配置文件路径
}
Config 包含框架配置选项
type Context ¶
Context 是Flow框架的上下文结构体,扩展了Gin的Context
func (*Context) Cache ¶
func (c *Context) Cache() interface{}
Cache 获取缓存实例 用户应在 Engine.Provide 中注册具体缓存类型,然后通过 Inject 获取
func (*Context) ConfigBool ¶
ConfigBool 获取布尔配置值
func (*Context) ConfigString ¶
ConfigString 获取字符串配置值
func (*Context) ConfigValue ¶
ConfigValue 获取指定键的配置值
func (*Context) Inject ¶
Inject 向上下文注入依赖 注意: target 必须是指向具体类型指针的指针,例如 var svc *MyService; c.Inject(&svc) 内部通过 dig 容器解析具体类型
func (*Context) SetCookie ¶
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie 设置 Cookie
type Engine ¶
Engine 是Flow框架的主结构体,封装了Gin引擎和依赖注入容器
func (*Engine) DELETE ¶
func (e *Engine) DELETE(relativePath string, handlers ...HandlerFunc)
DELETE 是对Handle("DELETE", path, handlers)的简便方法
func (*Engine) GET ¶
func (e *Engine) GET(relativePath string, handlers ...HandlerFunc)
GET 是对Handle("GET", path, handlers)的简便方法
func (*Engine) Group ¶
func (e *Engine) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
Group 创建一个新的路由组
func (*Engine) Handle ¶
func (e *Engine) Handle(httpMethod, relativePath string, handlers ...HandlerFunc)
Handle 注册处理函数到给定的HTTP方法和路径
func (*Engine) NewContext ¶
NewContext 创建Flow上下文
func (*Engine) OnShutdown ¶
OnShutdown 注册关闭钩子函数,priority 越小越先执行
func (*Engine) PATCH ¶
func (e *Engine) PATCH(relativePath string, handlers ...HandlerFunc)
PATCH 是对Handle("PATCH", path, handlers)的简便方法
func (*Engine) POST ¶
func (e *Engine) POST(relativePath string, handlers ...HandlerFunc)
POST 是对Handle("POST", path, handlers)的简便方法
func (*Engine) PUT ¶
func (e *Engine) PUT(relativePath string, handlers ...HandlerFunc)
PUT 是对Handle("PUT", path, handlers)的简便方法
func (*Engine) RegisterModule ¶
RegisterModule 注册单个模块到引擎
func (*Engine) RegisterModules ¶
RegisterModules 批量注册模块
func (*Engine) WithDatabase ¶
WithDatabase 配置数据库连接 传入各种配置选项,如直接的Config、ConnectionOption函数或配置结构
type HTTPError ¶
type HTTPError struct {
Code int `json:"code"`
Message string `json:"message"`
Details interface{} `json:"details,omitempty"`
}
HTTPError 表示HTTP错误
func NewHTTPError ¶
NewHTTPError 创建一个新的HTTP错误
func NewHTTPErrorWithDetails ¶
NewHTTPErrorWithDetails 创建一个带有详细信息的HTTP错误
type Logger ¶
type Logger interface {
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
}
Logger 定义Flow框架的日志接口 用户可以实现此接口来替换默认的日志行为
type Module ¶
type Module interface {
// Name 返回模块名称,用于日志和调试
Name() string
// Init 初始化模块:注册服务到DI容器
Init(e *Engine) error
}
Module 定义模块接口 模块是自包含的功能单元,负责向DI容器注册自己的服务和路由
type Option ¶
type Option func(*Engine)
选项函数类型定义
func WithConfigWatcher ¶
func WithConfigWatcher(callback func()) Option
WithConfigWatcher 返回一个监听配置变更的选项
func WithMiddleware ¶
func WithMiddleware(middleware ...HandlerFunc) Option
WithMiddleware 返回一个添加全局中间件的选项
func WithServiceProvider ¶
func WithServiceProvider(constructor interface{}) Option
WithServiceProvider 返回一个注册服务提供者的选项
func WithStaticFiles ¶
WithStaticFiles 返回一个配置静态文件服务的选项
type RoutableModule ¶
RoutableModule 可选接口,模块可以同时实现路由注册
type RouterGroup ¶
type RouterGroup struct {
RouterGroup *gin.RouterGroup
// contains filtered or unexported fields
}
RouterGroup 是Flow的路由组结构
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc)
DELETE 是对Handle("DELETE", path, handlers)的简便方法
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(relativePath string, handlers ...HandlerFunc)
GET 是对Handle("GET", path, handlers)的简便方法
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
Group 创建一个子路由组
func (*RouterGroup) Handle ¶
func (g *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc)
Handle 在路由组中注册处理函数
func (*RouterGroup) PATCH ¶
func (g *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc)
PATCH 是对Handle("PATCH", path, handlers)的简便方法
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(relativePath string, handlers ...HandlerFunc)
POST 是对Handle("POST", path, handlers)的简便方法
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc)
PUT 是对Handle("PUT", path, handlers)的简便方法
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middleware ...HandlerFunc) *RouterGroup
Use 添加路由组中间件
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
flow
command
|
|
|
Package db 提供数据库访问和仓储模式支持
|
Package db 提供数据库访问和仓储模式支持 |
|
cache
command
|
|
|
config_load
command
|
|
|
db_example
command
|
|
|
db_yaml_example
command
|
|
|
seeds
command
|
|
|
simple
command
|
|
|
Package ginmode 确保在gin包初始化前设置正确的模式
|
Package ginmode 确保在gin包初始化前设置正确的模式 |
|
pkg
|
|
|
Package test 提供测试支持工具和辅助函数
|
Package test 提供测试支持工具和辅助函数 |
|
Package validation 提供数据验证功能和自定义验证规则
|
Package validation 提供数据验证功能和自定义验证规则 |