rpcserver

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

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 DebugFlags struct {
	GinDebug    bool
	RequestLog  bool
	ResponseLog bool
}

type DebugResponse

type DebugResponse struct {
	Ip    string `json:"ip"`
	Value string `json:"value"`
}

type DebugUAResponse

type DebugUAResponse struct {
	BrowserName string `json:"browser_name"`
	DeviceType  string `json:"device_type"`
	OsName      string `json:"os_name"`
	OsPlatform  string `json:"os_platform"`
	DbPlatform  string `json:"db_platform"`
}

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 PagingResult struct {
	Offset int   `json:"offset"`
	Limit  int   `json:"limit"`
	Total  int64 `json:"total"`
}

type RouterProvider

type RouterProvider interface {
	ProvideRouter(*gin.Engine) *gin.Engine
}

type RpcServer

type RpcServer struct {
	RouterProvider RouterProvider
	Port           string
	DebugFlags     DebugFlags
	// contains filtered or unexported fields
}

func (*RpcServer) InitDefault

func (srv *RpcServer) InitDefault()

func (*RpcServer) Name

func (srv *RpcServer) Name() string

func (*RpcServer) Start

func (srv *RpcServer) Start()

func (*RpcServer) Stop

func (srv *RpcServer) Stop()

type RpcWrapper

type RpcWrapper struct {
	Flags RpcWrapperFlags
}

func (*RpcWrapper) ParsePagingGet

func (rpc *RpcWrapper) ParsePagingGet(c *gin.Context) (paging PagingParams, err error)

func (*RpcWrapper) Response

func (rpc *RpcWrapper) Response(c *gin.Context, status int, code string, msg string, data interface{})

func (*RpcWrapper) ResponseBadRequest

func (rpc *RpcWrapper) ResponseBadRequest(c *gin.Context, err error, userMessage string) bool

func (*RpcWrapper) ResponseDebug

func (rpc *RpcWrapper) ResponseDebug(c *gin.Context, status int, code string, msg string, debugMessage string, data interface{})

func (*RpcWrapper) ResponseEmptyField

func (rpc *RpcWrapper) ResponseEmptyField(c *gin.Context, name string, value string) bool

func (*RpcWrapper) ResponseEmptyParam

func (rpc *RpcWrapper) ResponseEmptyParam(c *gin.Context, name string, value string) bool

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

type TimeRangeParams struct {
	StartTime *time.Time
	EndTime   *time.Time
}

func NewTimeRange

func NewTimeRange(startTimestamp *int64, endTimestamp *int64) (v TimeRangeParams)

type TimeRangeRequest

type TimeRangeRequest struct {
	FromTime int64 `json:"from_time"`
	ToTime   int64 `json:"to_time"`
}

Jump to

Keyboard shortcuts

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