Documentation ¶
Index ¶
- Constants
- Variables
- func RequestLoggerMiddleware() gin.HandlerFunc
- func ResponseLoggerMiddleware() gin.HandlerFunc
- type DebugFlags
- type DebugResponse
- type DebugUAResponse
- type GeneralResponse
- type OrderParams
- type PagingOrderFilterRequest
- type PagingOrderRequest
- type PagingParams
- type PagingResponse
- type PagingResult
- type RouterProvider
- type RpcServer
- type RpcWrapper
- func (rpc *RpcWrapper) ParsePagingGet(c *gin.Context) (paging PagingParams, err error)
- func (rpc *RpcWrapper) Response(c *gin.Context, status int, code string, msg string, data interface{})
- func (rpc *RpcWrapper) ResponseBadRequest(c *gin.Context, err error, userMessage string) bool
- func (rpc *RpcWrapper) ResponseDebug(c *gin.Context, status int, code string, msg string, debugMessage string, ...)
- func (rpc *RpcWrapper) ResponseEmptyField(c *gin.Context, name string, value string) bool
- func (rpc *RpcWrapper) ResponseEmptyParam(c *gin.Context, name string, value string) bool
- func (rpc *RpcWrapper) ResponseError(c *gin.Context, err error) bool
- func (rpc *RpcWrapper) ResponseInternalServerError(c *gin.Context, err error) bool
- func (rpc *RpcWrapper) ResponseOK(c *gin.Context, data interface{})
- func (rpc *RpcWrapper) ResponsePaging(c *gin.Context, pagingResult PagingResult, data interface{}, list interface{})
- type RpcWrapperFlags
- type TimeRangeParams
- type TimeRangeRequest
Constants ¶
View Source
const CodeOK = "OK"
View Source
const OrderDirectionASC = "ASC"
View Source
const OrderDirectionDESC = "DESC"
View Source
const ShutdownTimeoutSeconds = 5
Variables ¶
View Source
var ( ErrBadRequest = "ErrBadRequest" ErrInternal = "ErrInternal" ErrNotFound = "ErrNotFound" )
Functions ¶
func RequestLoggerMiddleware ¶
func RequestLoggerMiddleware() gin.HandlerFunc
func ResponseLoggerMiddleware ¶
func ResponseLoggerMiddleware() gin.HandlerFunc
Types ¶
type DebugFlags ¶
type DebugResponse ¶
type DebugUAResponse ¶
type GeneralResponse ¶
type GeneralResponse struct { Code string `json:"code" example:"OK"` // Code is OK for normal cases and ErrXXXX for errors. Msg string `json:"msg"` // Msg is "" for normal cases and message for errors. DebugMsg string `json:"XXXdebug_msg,omitempty"` // XXXDebugMsg is "" for normal cases and debug message for errors. Data interface{} `json:"data,omitempty"` // Optional }
type OrderParams ¶
type OrderParams struct { OrderBy string `json:"order_by"` // DB column name. Empty string means no sorting. OrderDirection string `json:"order_direction"` // ASC or DESC }
func DefaultOrderParams ¶
func DefaultOrderParams(params OrderParams) OrderParams
func (*OrderParams) ToSqlOrderBy ¶
func (o *OrderParams) ToSqlOrderBy() (c interface{}, err error)
type PagingOrderFilterRequest ¶
type PagingOrderFilterRequest struct { PagingOrderRequest Filter string `json:"filter"` // Any search field supported. May not be supported. }
type PagingOrderRequest ¶
type PagingOrderRequest struct { PagingParams OrderParams }
type PagingParams ¶
type PagingParams struct { Offset int `json:"offset"` // Default to 0 Limit int `json:"limit"` // Default to 10 NeedTotal bool `json:"need_total"` // Default to false }
func DefaultPagingParams ¶
func DefaultPagingParams(params PagingParams) PagingParams
func (PagingParams) ToPageNumSize ¶
func (p PagingParams) ToPageNumSize() (pageNum int, pageSize int)
type PagingResponse ¶
type PagingResponse struct { GeneralResponse List interface{} `json:"list,omitempty"` // List is always the result list Size int `json:"size"` // Size is the result count in this response1 Total int64 `json:"total"` // Total is the total result in database Page int `json:"page"` // Page is the given params in the request starts from 1 }
type PagingResult ¶
type RpcServer ¶
type RpcServer struct { RouterProvider RouterProvider Port string DebugFlags DebugFlags // contains filtered or unexported fields }
func (*RpcServer) InitDefault ¶
func (srv *RpcServer) InitDefault()
type RpcWrapper ¶
type RpcWrapper struct {
Flags RpcWrapperFlags
}
func (*RpcWrapper) ParsePagingGet ¶
func (rpc *RpcWrapper) ParsePagingGet(c *gin.Context) (paging PagingParams, err error)
func (*RpcWrapper) ResponseBadRequest ¶
func (*RpcWrapper) ResponseDebug ¶
func (*RpcWrapper) ResponseEmptyField ¶
func (*RpcWrapper) ResponseEmptyParam ¶
func (*RpcWrapper) ResponseError ¶
func (rpc *RpcWrapper) ResponseError(c *gin.Context, err error) bool
func (*RpcWrapper) ResponseInternalServerError ¶
func (rpc *RpcWrapper) ResponseInternalServerError(c *gin.Context, err error) bool
func (*RpcWrapper) ResponseOK ¶
func (rpc *RpcWrapper) ResponseOK(c *gin.Context, data interface{})
func (*RpcWrapper) ResponsePaging ¶
func (rpc *RpcWrapper) ResponsePaging(c *gin.Context, pagingResult PagingResult, data interface{}, list interface{})
type RpcWrapperFlags ¶
type RpcWrapperFlags struct {
ReturnDetailError bool
}
type TimeRangeParams ¶
func NewTimeRange ¶
func NewTimeRange(startTimestamp *int64, endTimestamp *int64) (v TimeRangeParams)
type TimeRangeRequest ¶
Click to show internal directories.
Click to hide internal directories.