utils

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
	XtraceKey     = "trace_id"            //外部链路ID
	RequestIdKey  = "request_id"          //链路ID
	TimeFormat    = "2006-01-02 15:04:05" //默认时间
)

Variables

This section is empty.

Functions

func AddFormFile

func AddFormFile(writer *multipart.Writer, name, path string) error

Add a file to a multipart writer.

func AddParams

func AddParams(url_ string, params url.Values) string

Add params to a url string.

func ArrayToString

func ArrayToString(array []interface{}) string

func Base64Decode

func Base64Decode(code string) string

func Base64Encode

func Base64Encode(s string) string

func Base64URLDecode

func Base64URLDecode(data string) string

Base64URLDecode 因为Base64转码后可能包含有+,/,=这些不安全的URL字符串,所以要进行换字符 '+' -> '-' '/' -> '_' '=' -> ” 字符串长度不足4倍的位补"="

func Base64UrlSafeEncode

func Base64UrlSafeEncode(data string) string

func CheckParamFile

func CheckParamFile(params url.Values) bool

Does the params contain a file?

func CheckParamsType

func CheckParamsType(v interface{}) int

func CreateOrder

func CreateOrder() int64

CreateOrder 生成订单号

func EncodeURLParams

func EncodeURLParams(bm map[string]interface{}, order int) string

EncodeURLParams 获取sign 加密 order = 1 正序 order =2 倒叙

func Exists

func Exists(filePath string) bool

Exists 判断文件或目录是否存在

func Fail

func Fail(c *gin.Context)

func FailAuthMessage

func FailAuthMessage(c *gin.Context, message string)

func FailAuthsMessage

func FailAuthsMessage(c *gin.Context, message string)

func FailNotMessage

func FailNotMessage(c *gin.Context, message string)

func FailWithDetailed

func FailWithDetailed(c *gin.Context, data interface{}, message string)

func FailWithMessage

func FailWithMessage(c *gin.Context, message string)

func Find

func Find(slice []int, val int) (int, bool)

Find获取一个切片并在其中查找元素。如果找到它,它将返回它的密钥,否则它将返回-1和一个错误的bool。

func GenValidateCode

func GenValidateCode(width int) string

GenValidateCode 生成6位随机验证码

func GenerateTraceId

func GenerateTraceId() string

GenerateTraceId 获取链路TraceId

func GetAddressByIP

func GetAddressByIP(ipA string) string

GetAddressByIP 获取省市区通过ip

func GetClientIp

func GetClientIp() string

获取用户IP地址

func GetLocalIPs

func GetLocalIPs() (ips []string)

func GetLock

func GetLock(redisConn *redis.Client, lockName string, acquireTimeout, lockTimeOut time.Duration) (string, error)

GetLock acquireTimeout Get the lock timeout period, If no lock is obtained within this period, err will be returned here lockTimeOut Lock timeout to prevent deadlock, lock automatically unlocked by this time

func GetRandomString

func GetRandomString(l int) string

GetRandomString 获取随机字符串

func GetRandomString6

func GetRandomString6(n uint64) []byte

GetRandomString6 获取6位随机字符串

func GetRequestIdKey

func GetRequestIdKey(c *gin.Context) (requestId string)

GetRequestIdKey 获取链路ID

func GetString

func GetString(d interface{}) string

GetString 只能是map和slice

func InSliceString

func InSliceString(k string, s []string) bool

InSliceString string是否在[]string里面

func IsNil

func IsNil(obj interface{}) bool

func MD5V

func MD5V(str []byte, b ...byte) string

func Md5

func Md5(s string) string

Md5 md5

func MergeHeaders

func MergeHeaders(headers ...map[string]string) map[string]string

Merge headers(latter ones have higher priority)

func MergeOptions

func MergeOptions(options ...map[int]interface{}) map[int]interface{}

Merge options(latter ones have higher priority)

func Ok

func Ok(c *gin.Context)

func OkWithData

func OkWithData(c *gin.Context, data interface{})

func OkWithDetailed

func OkWithDetailed(c *gin.Context, data interface{}, message string)

func OkWithMessage

func OkWithMessage(c *gin.Context, message string)

func ReleaseLock

func ReleaseLock(redisConn *redis.Client, lockName, code string) bool

ReleaseLock var count = 0 // test assist

func RemoteIp

func RemoteIp(req *http.Request) string

RemoteIp 返回远程客户端的 IP,如 192.168.1.1

func Result

func Result(c *gin.Context, code int, data interface{}, msg string)

func SingCheng

func SingCheng(bm map[string]interface{}, sign string, order int) bool

SingCheng 获取sign加密对比 order = 1 正序 order =2 倒叙

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

func Strval

func Strval(value interface{}) string

Strval interface转string

func ToReader

func ToReader(v interface{}) *bytes.Reader

func ToUrlValues

func ToUrlValues(v interface{}) url.Values

func ZipFiles

func ZipFiles(filename string, files []string, oldForm, newForm string) error

Types

type Response

type Response struct {
	Code      int         `json:"code"`
	Data      interface{} `json:"data"`
	Msg       string      `json:"msg"`
	RequestID string      `json:"request_id"`
}

type Time

type Time struct {
	sql.NullTime
}

Time is a nullable time.Time. It supports SQL and JSON serialization. It will marshal to null if null.

func NewTime

func NewTime(t time.Time, valid bool) Time

NewTime creates a new Time.

func TimeFrom

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time that will always be valid.

func TimeFromPtr

func TimeFromPtr(t *time.Time) Time

TimeFromPtr creates a new Time that will be null if t is nil.

func (Time) Equal

func (t Time) Equal(other Time) bool

Equal returns true if both Time objects encode the same time or are both null. Two times can be equal even if they are in different locations. For example, 6:00 +0200 CEST and 4:00 UTC are Equal.

func (Time) ExactEqual

func (t Time) ExactEqual(other Time) bool

ExactEqual returns true if both Time objects are equal or both null. ExactEqual returns false for times that are in different locations or have a different monotonic clock reading.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero returns true for invalid Times, hopefully for future omitempty support. A non-null Time with a zero value will not be considered zero.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this time is null.

func (Time) MarshalText

func (t Time) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It returns an empty string if invalid, otherwise time.Time's MarshalText.

func (Time) Ptr

func (t Time) Ptr() *time.Time

Ptr returns a pointer to this Time's value, or a nil pointer if this Time is null.

func (*Time) SetValid

func (t *Time) SetValid(v time.Time)

SetValid changes this Time's value and sets it to be non-null.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

func (*Time) UnmarshalText

func (t *Time) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It has backwards compatibility with v3 in that the string "null" is considered equivalent to an empty string and unMarshaling will succeed. This may be removed in a future version.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Time) ValueOrZero

func (t Time) ValueOrZero() time.Time

ValueOrZero returns the inner value if valid, otherwise zero.

Jump to

Keyboard shortcuts

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