types

package
v0.0.0-...-948e8a5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each[T any](slice []T, f func(i int))

Each 对任意类型的切片或数组,进行遍历执行

func EscapeNilSlice

func EscapeNilSlice(v interface{}) error

EscapeNilSlice 将数据中所有的 nil 切片或数组,设置为长度为 0 的空数组,避免前端处理失败。 注意:必须使用指针传递,否则无法替换掉nil

func Ints

func Ints[T any](slice []T, f func(i int) int) []int

Ints 从任意类型的切片或数组,生成Int数组

func IntsMap

func IntsMap[T any](slice []T, mapper func(i int) (key, value int)) map[int][]int

IntsMap 从任意类型的切片或数组,生成映射表

func IsNil

func IsNil(v interface{}) bool

IsNil 是否为Nil

func RandDuration

func RandDuration(from, to time.Duration) time.Duration

RandDuration 生成 [from, to) 区间内的随机时间间隔

func RandString

func RandString(length int) string

RandString 生成长度为 length 的随机字符串

Types

type CodeError

type CodeError struct {
	// contains filtered or unexported fields
}

CodeError 带错误码的错误 支持自定义错误码,HTTP状态码,及原始错误 注意:不要直接对 CodeError 进行比较操作,可能因为设置了不同的 origin 而不相等

func NewCodeError

func NewCodeError(httpStatus int, errCode int, text string) CodeError

NewCodeError 创建带错误码的错误

func (CodeError) Code

func (e CodeError) Code() int

Code 实现 envelope/ErrorWithCode 接口

func (CodeError) Error

func (e CodeError) Error() string

Error 实现 error 接口

func (CodeError) HTTPCode

func (e CodeError) HTTPCode() int

HTTPCode 实现 envelope/ErrorWithHTTPCode 接口

func (CodeError) Origin

func (e CodeError) Origin() error

Origin 实现 envelope/ErrorWithOrigin 接口

func (CodeError) WithOrigin

func (e CodeError) WithOrigin(err error) CodeError

type ErrorWithCode

type ErrorWithCode interface {
	error
	Code() int
}

ErrorWithCode 支持自定义错误码的 error

type ErrorWithHTTPCode

type ErrorWithHTTPCode interface {
	error
	HTTPCode() int
}

ErrorWithHTTPCode 支持自定义HTTP状态码的 error

type ErrorWithOrigin

type ErrorWithOrigin interface {
	error
	Origin() error
}

ErrorWithOrigin 支持返回原始错误的 error

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type JSONDate

type JSONDate time.Time

JSONDate "YYYY-MM-DD"格式时间

func (JSONDate) MarshalJSON

func (d JSONDate) MarshalJSON() ([]byte, error)

func (JSONDate) String

func (d JSONDate) String() string

func (*JSONDate) UnmarshalJSON

func (d *JSONDate) UnmarshalJSON(bytes []byte) error

type JSONTime

type JSONTime time.Time

JSONTime "YYYY-MM-DD HH:MM:SS"格式时间

func (JSONTime) MarshalJSON

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

func (JSONTime) String

func (t JSONTime) String() string

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(bytes []byte) error

type JSONTimestamp

type JSONTimestamp time.Time

JSONTimestamp 时间戳格式时间

func (JSONTimestamp) MarshalJSON

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

func (JSONTimestamp) String

func (d JSONTimestamp) String() string

func (*JSONTimestamp) UnmarshalJSON

func (t *JSONTimestamp) UnmarshalJSON(bytes []byte) error

type SQLJSON

type SQLJSON string

SQLJSON JSON格式数据

func (*SQLJSON) Scan

func (j *SQLJSON) Scan(args interface{}) error

func (SQLJSON) Value

func (j SQLJSON) Value() (driver.Value, error)

type Secret

type Secret string

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

type StrInts

type StrInts string

StrInts 以","分隔的整数数组 常用于HTTP请求中表示id列表,或数据库字段存放id列表,

func NewStrInts

func NewStrInts[T Integer](slice []T) StrInts

NewStrInts 从切片新建 StrInts

func (StrInts) Slice

func (s StrInts) Slice() []int

Slice 将 StrInts 转化成切片

func (StrInts) String

func (s StrInts) String() string

type StrJSON

type StrJSON string

StrJSON 将字符串进行JSON序列化或反序列化 空字符串为`null`值,反之亦然

func (StrJSON) MarshalJSON

func (j StrJSON) MarshalJSON() ([]byte, error)

func (*StrJSON) UnmarshalJSON

func (j *StrJSON) UnmarshalJSON(data []byte) error

type StrValue

type StrValue string

func Env

func Env(name string, defaultValue string) StrValue

func (StrValue) Bool

func (v StrValue) Bool() (bool, error)

func (StrValue) Default

func (v StrValue) Default(value string) StrValue

func (StrValue) Float32

func (v StrValue) Float32() (float32, error)

func (StrValue) Float64

func (v StrValue) Float64() (float64, error)

func (StrValue) Int

func (v StrValue) Int() (int, error)

func (StrValue) Int16

func (v StrValue) Int16() (int16, error)

func (StrValue) Int32

func (v StrValue) Int32() (int32, error)

func (StrValue) Int64

func (v StrValue) Int64() (int64, error)

func (StrValue) Int8

func (v StrValue) Int8() (int8, error)

func (StrValue) IsEmpty

func (v StrValue) IsEmpty() bool

func (StrValue) String

func (v StrValue) String() string

func (StrValue) StringArray

func (v StrValue) StringArray() []string

func (StrValue) Uint

func (v StrValue) Uint() (uint, error)

func (StrValue) Uint16

func (v StrValue) Uint16() (uint16, error)

func (StrValue) Uint32

func (v StrValue) Uint32() (uint32, error)

func (StrValue) Uint64

func (v StrValue) Uint64() (uint64, error)

func (StrValue) Uint8

func (v StrValue) Uint8() (uint8, error)

type URI

type URI string

func (URI) String

func (u URI) String() string

func (URI) URL

func (u URI) URL() URL

func (URI) WithQuery

func (u URI) WithQuery(key string, value string) URI

type URL

type URL struct {
	Schema   string
	Endpoint string
	URI      URI
}

func (URL) String

func (u URL) String() string

func (URL) WithEndpoint

func (u URL) WithEndpoint(endpoint string) URL

func (URL) WithQuery

func (u URL) WithQuery(key string, value string) URL

func (URL) WithSchema

func (u URL) WithSchema(schema string) URL

Jump to

Keyboard shortcuts

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