helper

package
v0.0.0-...-3f61646 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: Apache-2.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	RequestHeaderClientIP             = "X-Forwarded-For"
	RequestHeaderTokenName            = "X-Solar-Token"
	RequestHeaderApp                  = "X-Solar-App"
	RequestHeaderPlatform             = "X-Solar-Platform"
	RequestHeaderClientType           = "X-Client-Type"
	RequestHeaderDeviceID             = "X-Device-ID"
	RequestHeaderTaotieDeviceID       = "X-Taotie-Device-ID"
	RequestHeaderLanguage             = "X-Language"
	RequestHeaderAppOffset_OWNER      = 0
	RequestHeaderAppOffset_DEVICETYPE = 1
	RequestHeaderAppOffset_MARKET     = 4

	ResponseHeaderTraceID = "X-Solar-Trace-ID"

	InternalRolesKey = "admin_user_role"
	UserIDKey        = "user_id"
	AppTypeKey       = "app_type"
	OpenIdKey        = "open_id"
	SessionKey       = "session_key"
	ExpirationKey    = "expiration"
	DeviceTypeKey    = "device_type"
	AppVersionKey    = "app_version"
	ClientTypeKey    = "client_type"
	ClientIp         = "clientip"
	TraceIDHexKey    = "trace_id_hex"
	SpanIDKey        = "span_id"
	ResponseCodeKey  = "response_code"
	InstIdKey        = "inst_id"
)

Variables

View Source
var (
	RoleListRoles = map[string]interface{}{}
)

Functions

func BoolAvailablePassword

func BoolAvailablePassword(pwd string) bool

func BoolErrorAppType

func BoolErrorAppType(appType string) bool

func BoolErrorClientType

func BoolErrorClientType(clientType string) bool

func BoolErrorDeviceType

func BoolErrorDeviceType(deviceType string) bool

func BoolErrorInternalClientType

func BoolErrorInternalClientType(clientType string) bool

func CheckAdminUserHasRole

func CheckAdminUserHasRole(userRoles []string, needRoles map[string]interface{}) bool

func CheckParamEmpty

func CheckParamEmpty(str string) error

CheckParamEmpty checks if parameter is empty.

func ErrorResponse

func ErrorResponse(ctx echo.Context, err error) error

* 错误返回

func GetAppType

func GetAppType(ctx echo.Context) string

GetAppType extracts app_type from context, login require 时写入

func GetAppVersion

func GetAppVersion(ctx echo.Context) string

GetAppVersion extracts app_version from context, login require 时写入

func GetClientIp

func GetClientIp(ctx echo.Context) string

func GetClientType

func GetClientType(ctx echo.Context) string

GetClientType extracts client_type from context, login require 时写入

func GetDeviceID

func GetDeviceID(req *http.Request) string

GetDeviceID fetches device ID from request header.

func GetDeviceType

func GetDeviceType(ctx echo.Context) string

GetDeviceType extracts device_type from context, login require 时写入

func GetHeaderXDevicetype

func GetHeaderXDevicetype(ctx echo.Context) string

func GetHeaderXMarket

func GetHeaderXMarket(ctx echo.Context) string

func GetHeaderXOwner

func GetHeaderXOwner(ctx echo.Context) string

func GetIdFromPath

func GetIdFromPath(ctx echo.Context) (int64, error)

GetIdFromPath 从url中获取ID

func GetLanguage

func GetLanguage(ctx echo.Context) string

func GetLimit

func GetLimit(ctx echo.Context, defaultLimit int64) int64

GetLimit 限制前端API调用传入的limit数量 防止过大

func GetOpenId

func GetOpenId(ctx echo.Context) string

GetOpenId extracts open_id from context, login require 时写入

func GetParamFromPath

func GetParamFromPath(ctx echo.Context, param string) (int64, error)

GetParamFromPath 从url中获取自定义int参数

func GetPlatformFromHeader

func GetPlatformFromHeader(ctx echo.Context) string

func GetSessionKey

func GetSessionKey(ctx echo.Context) string

GetSessionKey extracts session_key from context, login require 时写入

func GetTaotieDeviceID

func GetTaotieDeviceID(req *http.Request) string

GetTaotieDeviceID fetches taotie device ID from request header.

func GetUserId

func GetUserId(ctx echo.Context) int64

GetUserId extracts userId from context, login require 时写入

func GetUserRoles

func GetUserRoles(ctx echo.Context) []string

GetUserRoles extracts roles from context

func GetUserRolesStr

func GetUserRolesStr(ctx echo.Context) string

func MicroCtxFromEcho

func MicroCtxFromEcho(ec echo.Context) context.Context

MicroCtxFromEcho transforms echo.Context to micro context and add trace ID.

func RandomHex

func RandomHex() string

RandomHex generates a random hex.

func RandomInt

func RandomInt() int64

RandomInt generates a random int64.

func SetClientIp

func SetClientIp(ctx echo.Context, ip string)

func SuccessResponse

func SuccessResponse(ctx echo.Context, data interface{}, fields ...string) error

* 正确返回

func SuccessResponseNoETag

func SuccessResponseNoETag(ctx echo.Context, data interface{}, fields ...string) error

func TransferClientType

func TransferClientType(clientType string) string

Types

type Response

type Response struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

Response API正常返回体

func Payload

func Payload(data json.RawMessage, fields ...string) *Response

* Payload 构建API 返回体

Jump to

Keyboard shortcuts

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