Documentation ¶
Index ¶
- Constants
- func CommonJsonResult(ctx *gin.Context, code int, resp any)
- func Result(ctx *gin.Context, httpCode, code int, data interface{}, message string, ...)
- func ResultData(ctx *gin.Context, data interface{})
- func ResultError(ctx *gin.Context, err Error)
- func StartSpan(ctx context.Context, tracerName, spanName string) (context.Context, trace.Span)
- func Wrap[Request any, Response any](handler func(c *gin.Context, requestDTO *Request) (Response, error)) func(c *gin.Context)
- type Application
- type CallbackFunc
- type CallbackPosition
- type DatabaseIface
- type Error
- type GinApplication
- type LoggerIface
- type RedisConn
- type ResponseDTO
- type ResponseDataIface
Constants ¶
View Source
const (
VERSION = "v0.0.1"
)
Variables ¶
This section is empty.
Functions ¶
func ResultData ¶
Result default func Result 方法的默认值包装方法
func Wrap ¶
func Wrap[Request any, Response any](handler func(c *gin.Context, requestDTO *Request) (Response, error)) func(c *gin.Context)
type AddUserResponse struct { ID int64 `json:"id,omitempty"` }
func (s *Service) addUser(ctx *gin.Context, req *AddUserRequest) (*AddUserResponse, error) { // 处理请求... }
func main() { router := gin.Default() router.POST("/user/add", Wrap(s.addUser)) }
Types ¶
type Application ¶
type Application struct { Name string Host string Port int64 Config *config.Config LoadConfig func() error SetupVars func() error // RegisterModule func() error RegisterCallback map[CallbackPosition]CallbackFunc }
type CallbackFunc ¶
type CallbackFunc func() error
type CallbackPosition ¶
type CallbackPosition int
const ( // 在 InitGlobalConfig 后调用 POSITION_GLOBAL_CONFIG CallbackPosition = iota + 1 // 在 InitGlobalLogger 后调用 POSITION_INIT_LOGGER // 在 Module Register 后调用 POSITION_MODULE_REGISTER // 调用 LoadConfig 方法后 POSITION_LOAD_CONFIG // 调用 SetupVars 方法后 POSITION_SETUP_VARS // 调用 New 方法后 POSITION_NEW )
type DatabaseIface ¶
var Database DatabaseIface
type Error ¶
type GinApplication ¶
type LoggerIface ¶
type LoggerIface interface { // 普通日志 Info(ctx context.Context, args ...interface{}) Infof(ctx context.Context, format string, args ...interface{}) // 警告日志 Warn(ctx context.Context, args ...interface{}) Warnf(ctx context.Context, format string, args ...interface{}) // 错误日志 Error(ctx context.Context, args ...interface{}) Errorf(ctx context.Context, format string, args ...interface{}) }
var Logger LoggerIface
type ResponseDTO ¶
type ResponseDTO struct { Code int `json:"code"` Msg string `json:"msg"` Data any `json:"data"` Status string `json:"status"` }
func (*ResponseDTO) GetStatus ¶
func (r *ResponseDTO) GetStatus() string
type ResponseDataIface ¶
type ResponseDataIface interface {
GetStatus() string
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.