common

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 12 Imported by: 13

Documentation

Index

Constants

View Source
const (
	AuthorizationKey    = "authorization"
	SetAuthorizationKey = "x-set-authorization"
	MsgKey              = "msg"
	UserIDKey           = "x-vaala-userid"
	EndpointKey         = "endpoint"
	IpAddrKey           = "ipaddr"
	HeaderKey           = "header"
	MethodKey           = "method"
	UAKey               = "User-Agent"
	ContentTypeKey      = "Content-Type"
	TraceIDKey          = "TraceID"
	TokenKey            = "token"
	FRPAuthTokenKey     = "token"
	ErrKey              = "err"
	UserInfoKey         = "x-vaala-userinfo"
	FRPClientIDKey      = "x-vaala-frp-client-id"
)
View Source
const (
	ErrInvalidRequest   = "invalid request"
	ErrUserInfoNotValid = "user info not valid"
	ErrInternalError    = "internal error"
	ErrParamNotValid    = "param not valid"
	ErrDB               = "database error"
	ErrNotFound         = "data not found"
	ErrCodeNotFound     = "code not found"
	ErrCodeAlreadyUsed  = "code already used"
)
View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusFailed  = "failed"
	StatusDone    = "done"
)
View Source
const (
	CliTypeServer = "server"
	CliTypeClient = "client"
)
View Source
const (
	DefaultServerID    = "default"
	DefaultAdminUserID = 1
)
View Source
const (
	ReqSuccess = "success"
)
View Source
const (
	TimeLayout = time.RFC3339
)

Variables

This section is empty.

Functions

func ErrResp

func ErrResp[T RespType](c *gin.Context, origin *T, err string)

func ErrUnAuthorized

func ErrUnAuthorized(c *gin.Context, err string)

func GetProtoRequest

func GetProtoRequest[T ReqType](c *gin.Context) (r *T, err error)

func GetServerMessageRequest

func GetServerMessageRequest[T ReqType](b []byte, r *T, trans func(b []byte, m protoreflect.ProtoMessage) error) (err error)

func GetUserInfo

func GetUserInfo(c context.Context) models.UserInfo

func GlobalClientID

func GlobalClientID(username, clientType, clientID string) string

func OKResp

func OKResp[T RespType](c *gin.Context, origin *T)

func ProtoResp

func ProtoResp[T RespType](origin *T) (*pb.ClientMessage, error)

func Wrapper

func Wrapper[T ReqType, U RespType](handler func(context.Context, *T) (*U, error)) func(c *gin.Context)

func WrapperServerMsg

func WrapperServerMsg[T ReqType, U RespType](req *pb.ServerMessage, handler func(context.Context, *T) (*U, error)) *pb.ClientMessage

Types

type Result

type Result struct {
	Code int         `json:"code,omitempty"`
	Msg  string      `json:"msg,omitempty"`
	Data gin.H       `json:"data,omitempty"`
	Body interface{} `json:"body,omitempty"`
}

func Err

func Err(msg string) *Result

func OK

func OK(msg string) *Result

func UnAuth

func UnAuth(msg string) *Result

func (*Result) WithBody

func (r *Result) WithBody(body interface{}) *Result

func (*Result) WithData

func (r *Result) WithData(data gin.H) *Result

func (*Result) WithKeyValue

func (r *Result) WithKeyValue(key string, value interface{}) *Result

func (*Result) WithMsg

func (r *Result) WithMsg(message string) *Result

Jump to

Keyboard shortcuts

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