typ

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHex = errors.New("the provided hex string is not a valid ObjectID")

ErrInvalidHex indicates that a hex string cannot be converted to an ObjectID.

Functions

func ContainsChinese added in v0.3.9

func ContainsChinese(text string) bool

ContainsChinese 是否存在中文字符

func HidePhoneMiddle added in v0.1.0

func HidePhoneMiddle(phone string) string

HidePhoneMiddle eg:86-187****0987

func InSlice added in v0.3.9

func InSlice(str string, s []string) bool

func IsChinesePhone added in v0.1.0

func IsChinesePhone(phone string) bool

IsChinesePhone

func IsLetterOrDigit added in v0.3.9

func IsLetterOrDigit(s string) bool

IsLetterOrDigit 是否字母或数字

func IsPhone added in v0.1.0

func IsPhone(phone string) bool

IsPhone

func IsValidObjectID added in v0.3.9

func IsValidObjectID(s string) bool

IsValidObjectID returns true if the provided hex string represents a valid ObjectID and false if not.

func Md5String added in v0.3.9

func Md5String(s string, multi ...string) string

Md5String md5 strings

func PasswordSlatMD5 added in v0.3.9

func PasswordSlatMD5(password, slat string) string

PasswordSlatMD5 md5 pwd & slat

func RandAlphaNumString added in v0.3.9

func RandAlphaNumString(strLen int, lower ...bool) string

RandAlphaNumString rand x len string

func RandNumCode added in v0.3.9

func RandNumCode(strLen int) string

RandNumCode rand number verify code, max len 20

func SetReqDataContext added in v0.3.3

func SetReqDataContext(ctx context.Context, data ReqData) context.Context

func SliceRemoveDuplicate added in v0.3.5

func SliceRemoveDuplicate(x interface{}, fn func(i, j int) bool)

SliceRemoveDuplicate 切片去重

func StrRangeN added in v0.3.9

func StrRangeN(str string, n int) string

StrRangeN 取字符串 前后部分,总计N个字符 这样写主要是处理中文乱码问题 注意,返回非严格N字符

func Substr added in v0.3.9

func Substr(str string, start, length int) string

Substr if start < 0, desc, if arg invalid, return str [start,start+length)

func Substring added in v0.3.9

func Substring(str string, start, end int) string

Substring if start < 0, desc, if arg invalid, return str [start,end)

func TrimStringToFloat added in v0.3.7

func TrimStringToFloat(s string) (float64, error)

func TrimStringToInt added in v0.3.7

func TrimStringToInt(s string) (int, error)

func UniqueSlice added in v0.3.9

func UniqueSlice(s []string, isDropEmpty bool) []string

UniqueSlice 切片去重,是否去掉空字符串,切片顺序不变

Types

type BaseResp added in v0.3.3

type BaseResp struct {
	errc.Error
	TraceID string `json:"traceId"`
}

func NewBaseResp added in v0.3.3

func NewBaseResp(code int, msg string) *BaseResp

func (*BaseResp) WriteTraceID added in v0.3.3

func (b *BaseResp) WriteTraceID(ctx context.Context) *BaseResp

type DataResp added in v0.3.3

type DataResp struct {
	*BaseResp
	Data interface{} `json:"data"`
}

func NewDataResp added in v0.3.3

func NewDataResp(baseResp *BaseResp, data interface{}) *DataResp

func Resp added in v0.3.3

func Resp(data interface{}, err error, ctx ...context.Context) *DataResp

type IdOmitReq

type IdOmitReq struct {
	Id int64 `json:"id" form:"id" binding:"omitempty,min=1"`
}

type IdReq

type IdReq struct {
	Id int64 `json:"id" form:"id" binding:"required,gt=0"`
}

type IntSplit added in v0.3.7

type IntSplit string

func (IntSplit) Unmarshal added in v0.3.7

func (is IntSplit) Unmarshal(sep string) ([]int, error)

type IsLimit

type IsLimit int

func (IsLimit) All

func (i IsLimit) All() bool

func (IsLimit) Val

func (i IsLimit) Val() int

type ListResp

type ListResp struct {
	Count int64       `json:"count"`
	List  interface{} `json:"list"`
}

type LoginReq

type LoginReq struct {
	// 4-24
	Username string `json:"username" binding:"required,gte=4,lte=24"`
	// must md5
	Password string `json:"password" binding:"required,len=32"`
}

type LoginResp

type LoginResp struct {
	Token    string `json:"token"`
	Nickname string `json:"nickname"`
	Role     string `json:"role"`
}

type ObjectID added in v0.3.9

type ObjectID [12]byte

ObjectID is the BSON ObjectID type.

var NilObjectID ObjectID

NilObjectID is the zero value for ObjectID.

func NewObjectID added in v0.3.9

func NewObjectID() ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromTimestamp added in v0.3.9

func NewObjectIDFromTimestamp(timestamp time.Time) ObjectID

NewObjectIDFromTimestamp generates a new ObjectID based on the given time.

func ObjectIDFromHex added in v0.3.9

func ObjectIDFromHex(s string) (ObjectID, error)

ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.

func (ObjectID) Hex added in v0.3.9

func (id ObjectID) Hex() string

Hex returns the hex encoding of the ObjectID as a string.

func (ObjectID) IsZero added in v0.3.9

func (id ObjectID) IsZero() bool

IsZero returns true if id is the empty ObjectID.

func (ObjectID) MarshalJSON added in v0.3.9

func (id ObjectID) MarshalJSON() ([]byte, error)

MarshalJSON returns the ObjectID as a string

func (ObjectID) String added in v0.3.9

func (id ObjectID) String() string

func (ObjectID) Timestamp added in v0.3.9

func (id ObjectID) Timestamp() time.Time

Timestamp extracts the time part of the ObjectId.

func (*ObjectID) UnmarshalJSON added in v0.3.9

func (id *ObjectID) UnmarshalJSON(b []byte) error

UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 24 bytes long, it will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes long, it will be populated with the BSON representation of the ObjectID. This method also accepts empty strings and decodes them as NilObjectID. For any other inputs, an error will be returned.

type PageReq

type PageReq struct {
	Page int `json:"page" form:"page,default=1" binding:"required,gte=1"`
	Size int `json:"size" form:"size,default=20" binding:"required,gte=1,lte=1000"`
}

func (PageReq) LimitStart added in v0.0.4

func (req PageReq) LimitStart() (limit, start int)

func (PageReq) Skip added in v0.0.4

func (req PageReq) Skip() int64

type ReqData added in v0.3.3

type ReqData struct {
	Route       string
	RemoteAddr  string
	Uid         string
	Body        string
	Msg         string // 补充信息
	InternalErr string
	// contains filtered or unexported fields
}

func GetReqDataContext added in v0.3.3

func GetReqDataContext(ctx context.Context) ReqData

type StringSplit added in v0.3.7

type StringSplit string

func (StringSplit) Has added in v0.3.9

func (ss StringSplit) Has(v string, sep string) bool

func (StringSplit) Marshal added in v0.3.7

func (ss StringSplit) Marshal(val []string, sep string) StringSplit

func (StringSplit) Unmarshal added in v0.3.7

func (ss StringSplit) Unmarshal(sep string) []string

type TimeStringReq

type TimeStringReq struct {
	// format 2006-01-02 15:04:05
	StartTime string `json:"startTime" form:"startTime"`
	EndTime   string `json:"endTime" form:"endTime"`
}

func (TimeStringReq) FieldMgoBson added in v0.0.4

func (req TimeStringReq) FieldMgoBson() (map[string]interface{}, bool)

func (TimeStringReq) FieldSQLCond

func (req TimeStringReq) FieldSQLCond(field string) []string

type TimestampReq

type TimestampReq struct {
	// Unix timestamp Sec
	StartTimestamp int64 `json:"startTimestamp" form:"startTimestamp,default=0" binding:"omitempty,min=0"`
	EndTimestamp   int64 `json:"endTimestamp" form:"endTimestamp,default=0" binding:"omitempty,gtefield=StartTimestamp"`
}

func (TimestampReq) FieldMgoBson added in v0.0.4

func (req TimestampReq) FieldMgoBson() (map[string]interface{}, bool)

func (TimestampReq) FieldSQLCond

func (req TimestampReq) FieldSQLCond(field string) []string

type UidOmitReq

type UidOmitReq struct {
	Uid int64 `json:"uid" form:"uid" binding:"omitempty,min=1"`
}

type UidReq

type UidReq struct {
	Uid int64 `json:"uid" form:"uid" binding:"required,min=1"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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