utils

package
v0.0.0-...-9776187 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

* 在请求上下文上设置和获取指定的key/val

小助手函数,辅助业务逻辑的函数

* http返回json格式和http code返回处理

Index

Constants

View Source
const (
	HttpSuccessCode = 200 // http ok 200
	HttpErrorCode   = 500 // http error 500
	ApiSuccessCode  = 0   // api success
)

Variables

This section is empty.

Functions

func ApiError

func ApiError(w http.ResponseWriter, code int, message string)

ApiError 错误处理code,message

func ApiSuccess

func ApiSuccess(w http.ResponseWriter, message string, data interface{})

ApiSuccess 请求成功返回结果 data,message

func ContextGet

func ContextGet(r *http.Request, key interface{}) interface{}

ContextGet 从请求上下文获取指定的key值

func ContextSet

func ContextSet(r *http.Request, key, val interface{}) *http.Request

ContextSet 将指定的key/val设置到上下文中

func GetDeviceByUa

func GetDeviceByUa(ua string) string

GetDeviceByUa 根据ua获取设备名称

func GetStringByCtx

func GetStringByCtx(ctx context.Context, key string) string

GetStringByCtx 从上下文获取字符串类型的key

func HttpCode

func HttpCode(w http.ResponseWriter, httpCode int, message string)

HttpCode 指定http code,message返回

func Json

func Json(w http.ResponseWriter, data interface{})

Json 直接返回json data数据

Types

type EmptyArray

type EmptyArray []struct{}

EmptyArray 空数组[]兼容其他语言php,js,python等

type H

type H map[string]interface{}

H map短类型声明

Jump to

Keyboard shortcuts

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