Documentation
¶
Index ¶
- Variables
- func Check(v interface{}) error
- func NewCustomHTTPErrorHandler(e *echo.Echo, logf Logf) echo.HTTPErrorHandler
- func NewCustomValidator() echo.Validator
- type App
- type BizErr
- type Checker
- type Config
- type Context
- type ErrType
- type ErrorArray
- type ErrorData
- type FineErr
- type Job
- type Log
- type Logf
- type Migrator
- type Module
- type ModuleFunc
- type OnShutdown
- type PubSub
- type Redis
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUnsupported 表示Checker遇到了不支持的情况 ErrUnsupported = errors.New("Checker not support this type") )
Functions ¶
func NewCustomHTTPErrorHandler ¶
func NewCustomHTTPErrorHandler(e *echo.Echo, logf Logf) echo.HTTPErrorHandler
NewCustomHTTPErrorHandler 构造 echo.HTTPErrorHandler
func NewCustomValidator ¶
NewCustomValidator 构造echo.Validator实例
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) RegisterModules ¶
RegisterModules 注册模块,详情见Module
type BizErr ¶
type BizErr struct {
Type ErrType
// contains filtered or unexported fields
}
func NewBadArgs ¶
type Checker ¶
type Checker interface {
// Check 校验v,并返回结构化的错误信息ErrorArray或者其他error
Check(v interface{}) error
}
Checker 校验器
type Config ¶
type Config struct {
APIAddr string `toml:"api_addr"`
MysqlDSN string `toml:"mysql_dsn"`
EnableDBLog bool `toml:"enable_db_log"`
Log Log `toml:"log"`
Redis Redis `toml:"redis"`
}
Config 配置
type Context ¶
type Context interface {
// GET 注册HTTP GET路由
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc)
// POST 注册HTTP POST路由
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc)
// 注册中间件
Use(middlewares ...echo.MiddlewareFunc)
// Schedule 注册定时任务
Schedule(expr string, job Job)
// Publish 发布事件
Publish(topic string, payload string)
// Subscribe 订阅事件
Subscribe(topic string, cb func(string))
// GetDB 获取数据库连接实例
GetDB() *gorm.DB
// GetRedis 获取Redis连接实例
GetRedis() *redis.Client
// Logf 日志方法
Logf(format string, args ...interface{})
// Provide 提供资源,和Take配套使用
Provide(id string, obj interface{})
// Take 获取资源,即通过Provide提供的资源
Take(id string) interface{}
// RegisterShutdown 注册停止服务前调用的方法
// 当服务停止时,会先停止HTTP服务、定时任务、事件系统,当这3者停止后,
// 调用通过ReigsterShutdown注册的方法
RegisterShutdown(hook OnShutdown)
}
Context 是模块初始化时可获取的资源和可调用的方法
type ErrorArray ¶
type ErrorArray []ErrorData
ErrorArray 是字段的错误信息
func (ErrorArray) Error ¶
func (eArr ErrorArray) Error() string
type ErrorData ¶
type ErrorData struct {
Field string `json:"field"` // 字段
Title string `json:"title"` // 字段标题
Errors []string `json:"errors"` // 错误
}
ErrorData 是某个字段的校验错误
type FineErr ¶
type FineErr struct {
Code int
Message string
Caller string
// contains filtered or unexported fields
}
FineErr 是一个可以对用户友好点的错误
func TraceError ¶
type Log ¶
type Log struct {
Level string `toml:"level"` // 日志级别
Output string `toml:"output"` // 文件路径(例子:log/http.log)或者`stdout`
MaxSize int `toml:"max_size"` // 单个日志文件的大小上限,单位MB
MaxBackups int `toml:"max_backups"` // 最多保留几个日志文件
MaxAge int `toml:"max_age"` // 保留天数
Compress bool `toml:"compress"` // 是否压缩
}
Log 日志配置
type Module ¶
type Module interface {
Init(ac Context)
}
Module 是模块 设定这个接口的作用是把繁杂的系统组成分离成独立的部分 对具体什么是模块并没有任何约束,可以:
提供HTTP服务 执行定时任务 独立存在的一段for循环 仅仅打印一段话 等等
只要最终包装成Module接口传入RegisterModules方法即可 可以查看samples中的项目找找感觉
Source Files
¶
Click to show internal directories.
Click to hide internal directories.