utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For" // 获取真实ip
	XRealIP       = "X-Real-IP"       // 获取真实ip
)
View Source
const LogKey = "request-id"

Variables

View Source
var Errno = map[uint32]string{
	400: "系统错误",
}
View Source
var (
	SystemErr = Err(400)
)

Functions

func Err

func Err(code uint32) (err error)

func GenValidateCode

func GenValidateCode(width int) string

生成6位随机验证码

func GetAddressByIP

func GetAddressByIP(ipA string) string

获取省市区通过ip

func GetLock

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

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

获取随机字符串

func GetRandomString6

func GetRandomString6(n uint64) []byte

获取6位随机字符串

func Md5

func Md5(key ...string) string

func ReleaseLock

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

var count = 0 // test assist

func RemoteIp

func RemoteIp(req *http.Request) string

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

Types

type HeaderParam

type HeaderParam struct {
	AppID     string `header:"app-id" binding:"required"`
	AppName   string `header:"app-name" binding:"required"`
	RequestID string `header:"request-id"`
}

type Resp

type Resp struct{}

func (*Resp) Fail

func (res *Resp) Fail(c *gin.Context, err error)

func (*Resp) Suc

func (res *Resp) Suc(c *gin.Context, data interface{}, msg ...string)

type RspError

type RspError struct {
	Code uint32
	Msg  string
}

RspError

func (*RspError) Error

func (re *RspError) Error() string

func (*RspError) Render

func (re *RspError) Render() (code uint32, msg string)

Render

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

UnmarshalJSON implements json.Unmarshaler. It supports string and null input.

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