Documentation ¶
Index ¶
- Constants
- type CommonResponse
- func (r *CommonResponse) SetCode(code int64) *CommonResponse
- func (r *CommonResponse) SetData(data interface{}) *CommonResponse
- func (r *CommonResponse) SetMessage(message string) *CommonResponse
- func (r *CommonResponse) ToBytes() []byte
- func (r *CommonResponse) ToString() string
- func (r *CommonResponse) Unmarshal(data []byte) error
- type NotifyType
- type RespCodeType
- func (s RespCodeType) IsSuccess() bool
- func (s RespCodeType) ToInt() int
- func (s RespCodeType) ToInt16() int16
- func (s RespCodeType) ToInt32() int32
- func (s RespCodeType) ToInt64() int64
- func (s RespCodeType) ToInt8() int8
- func (s RespCodeType) ToString() string
- func (s *RespCodeType) UnmarshalJSON(b []byte) error
- type SafeJsonNumber
- type SignatureData
- func (s *SignatureData) CreateSignature(prvKey string) (string, error)
- func (s *SignatureData) SetNonce(nonce string) *SignatureData
- func (s *SignatureData) SetOperator(operator string) *SignatureData
- func (s *SignatureData) SetSign(sign string) *SignatureData
- func (s *SignatureData) VerifySignature(pubKey string) error
- type Time
- func (t Time) Add(second time.Duration) time.Time
- func (t Time) FormatYmd(withSeparator bool) string
- func (t Time) GetDateScope(scope string) time.Time
- func (t Time) GetRawTime() time.Time
- func (t Time) IsZero() bool
- func (t Time) MarshalJSON() ([]byte, error)
- func (t *Time) Scan(v interface{}) error
- func (t Time) ScopeName(scope string) string
- func (t Time) String() string
- func (t Time) StringByFormat(format string) stringdeprecated
- func (t Time) Timestamp() int64
- func (t *Time) UnmarshalJSON(data []byte) (err error)
- func (t Time) Value() (driver.Value, error)
- func (t Time) Year() int
- type VersionString
- func (v VersionString) EqualsTo(v2Str VersionString) (bool, error)
- func (v VersionString) GreaterOrEqualThan(v2Str VersionString) (bool, error)
- func (v VersionString) GreaterThan(v2Str VersionString) (bool, error)
- func (v VersionString) LessOrEqualThan(v2Str VersionString) (bool, error)
- func (v VersionString) LessThan(v2Str VersionString) (bool, error)
- func (v VersionString) String() string
Constants ¶
const EmptyTime = "0000-00-00 00:00:00"
EmptyTime 空时间,各种数据库,以及下游可能会返回该时间
const Format = "2006-01-02 15:04:05"
Format 标准格式
const Format1 = "2006-01-02 15:04"
const SimpleFormat = "2006-01-02"
SimpleFormat 添加简易格式,比如 Y-m-d
const SimpleFormat2 = "2006.01.02"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommonResponse ¶
type CommonResponse struct { Code RespCodeType `json:"code"` Data interface{} `json:"data"` Message string `json:"message"` }
func NewCommonResponse ¶
func NewCommonResponse() *CommonResponse
func NewSuccessResponse ¶
func NewSuccessResponse() *CommonResponse
func (*CommonResponse) SetCode ¶
func (r *CommonResponse) SetCode(code int64) *CommonResponse
func (*CommonResponse) SetData ¶
func (r *CommonResponse) SetData(data interface{}) *CommonResponse
func (*CommonResponse) SetMessage ¶
func (r *CommonResponse) SetMessage(message string) *CommonResponse
func (*CommonResponse) ToBytes ¶
func (r *CommonResponse) ToBytes() []byte
func (*CommonResponse) ToString ¶
func (r *CommonResponse) ToString() string
func (*CommonResponse) Unmarshal ¶
func (r *CommonResponse) Unmarshal(data []byte) error
type NotifyType ¶
type NotifyType int64
const ( RequestAuthNotifyType NotifyType = 1 //请求授权消息类型 ConfirmAuthNotifyType NotifyType = 2 //确认并接受授权的消息类型 DenyAuthNotifyType NotifyType = 3 //拒绝授权的消息类型 RevokeAuthNotifyType NotifyType = 4 //撤销授权的消息类型 RequestExchangeOwnershipNotifyType NotifyType = 5 //请求交换所有权消息类型 )
func (NotifyType) ToInt ¶
func (s NotifyType) ToInt() int
func (NotifyType) ToInt16 ¶
func (s NotifyType) ToInt16() int16
func (NotifyType) ToInt32 ¶
func (s NotifyType) ToInt32() int32
func (NotifyType) ToInt64 ¶
func (s NotifyType) ToInt64() int64
func (NotifyType) ToInt8 ¶
func (s NotifyType) ToInt8() int8
func (NotifyType) ToString ¶
func (s NotifyType) ToString() string
func (*NotifyType) UnmarshalJSON ¶
func (s *NotifyType) UnmarshalJSON(b []byte) error
type RespCodeType ¶
type RespCodeType int64
func (RespCodeType) IsSuccess ¶
func (s RespCodeType) IsSuccess() bool
func (RespCodeType) ToInt ¶
func (s RespCodeType) ToInt() int
func (RespCodeType) ToInt16 ¶
func (s RespCodeType) ToInt16() int16
func (RespCodeType) ToInt32 ¶
func (s RespCodeType) ToInt32() int32
func (RespCodeType) ToInt64 ¶
func (s RespCodeType) ToInt64() int64
func (RespCodeType) ToInt8 ¶
func (s RespCodeType) ToInt8() int8
func (RespCodeType) ToString ¶
func (s RespCodeType) ToString() string
func (*RespCodeType) UnmarshalJSON ¶
func (s *RespCodeType) UnmarshalJSON(b []byte) error
type SafeJsonNumber ¶
SafeJsonNumber 安全的数字,比json.Number 更安全,允许解析一些不合法数据 常见于一些坑爹的case:
1.未赋值情况: { "number" : "" }, 此时解析为:0 2.赋值空对象: { "number" : "{}" }, 此时解析为:0 3.赋值空数组: { "number" : "[]" }, 此时解析为:0
其他场景都将按照: json.Number 本身去解析
func NewJsonNumberFromInt ¶
func NewJsonNumberFromInt(value int) *SafeJsonNumber
func NewJsonNumberFromInt32 ¶
func NewJsonNumberFromInt32(value int32) *SafeJsonNumber
func NewJsonNumberFromInt64 ¶
func NewJsonNumberFromInt64(value int64) *SafeJsonNumber
func (*SafeJsonNumber) ToFloat64 ¶
func (d *SafeJsonNumber) ToFloat64() float64
func (*SafeJsonNumber) ToInt ¶
func (d *SafeJsonNumber) ToInt() int
func (*SafeJsonNumber) UnmarshalJSON ¶
func (d *SafeJsonNumber) UnmarshalJSON(b []byte) error
type SignatureData ¶
type SignatureData struct { OperatorDoi string `json:"operator_doi" form:"operator_doi" binding:"required"` //操作者的doi,在不同的场景中,可能为DW或DU SignatureNonce string `json:"signature_nonce" form:"operator_doi" binding:"required"` //唯一随机数,用于防止网络重放攻击。用户在不同请求间要使用不同的随机值,建议使用通用唯一识别码UUID(Universally Unique Identifier) Signature string `json:"signature" form:"operator_doi" binding:"required"` //对请求进行秘钥签名 }
func NewSignatureData ¶
func NewSignatureData() *SignatureData
func NewSignatureDataWithSign ¶
func NewSignatureDataWithSign(operator, prvKey string) *SignatureData
func (*SignatureData) CreateSignature ¶
func (s *SignatureData) CreateSignature(prvKey string) (string, error)
CreateSignature 签名:采用sha256算法进行签名并输出为hex格式(私钥PKCS8格式)
func (*SignatureData) SetNonce ¶
func (s *SignatureData) SetNonce(nonce string) *SignatureData
func (*SignatureData) SetOperator ¶
func (s *SignatureData) SetOperator(operator string) *SignatureData
func (*SignatureData) SetSign ¶
func (s *SignatureData) SetSign(sign string) *SignatureData
func (*SignatureData) VerifySignature ¶
func (s *SignatureData) VerifySignature(pubKey string) error
VerifySignature 验签:对采用sha256算法进行签名后转base64格式的数据进行验签
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time 时间格式
时区:
1.当使用Time解析时间字符串:"Y-m-d H:i:s"的时候,都会自动转换为北京时间! 2.统一使用CST时区,以便和上下游统一
json解析:
1.在json结构体中使用 Time 会自动进行格式转换,生成对应的时间;比如mysql、rpc、redis的返回值 2.默认支持:Y-m-d H:i:s格式,更多格式参考 UnmarshalJSON 以及对应的单测
json编码:
1.Time的数据在进行marshal的时候会自动调用 Format 格式进行设置
空时间 EmptyTime:
1.golang的time包不支持解析和编码 EmptyTime 格式的数据,当解析的时候会生成 0001-01-01 00:00:00的时间 但是我们的业务系统明显不期望有这种转换,所以 Time 包会将空时间数据,继续特殊处理为 EmptyTime 2.如果需要判断空时间,使用 IsZero()
func NewTimeFromSimpleString ¶ added in v1.0.2
NewTimeFromSimpleString 基于字符串格式构建,必须是: Y-m-d
func NewTimeFromSimpleString2 ¶ added in v1.0.2
NewTimeFromSimpleString2 基于字符串格式构建,必须是: Y.m.d
func NewTimeFromString ¶
NewTimeFromString 基于字符串格式构建,必须是: Y-m-d H:i:s
func (Time) FormatYmd ¶
FormatYmd 按照Ymd格式格式化 withSeparator 是否带有分割线,如果为true,则格式为2022-03-18 如果为false,不带分割线,比如20220318
func (Time) MarshalJSON ¶
func (Time) StringByFormat
deprecated
func (*Time) UnmarshalJSON ¶
UnmarshalJSON 支持格式如下:
- Y-m-d H:i:s 格式的时间字符串,将会按照北京时区解析
- 秒级别时间戳,字符串/数字:"1650445202" / 1650445202
- 毫秒级时间戳,字符串/数字: "1655976744820" / 1655976744820
- 毫秒级时间戳,字符串: "1655976744820"
- 科学计数法格式,字符串/数字: "1.657886194E9",1.657886194E9
- Y-m-d 格式, 将会按照北京时区解析
所以在底层做兼容
type VersionString ¶
type VersionString string
VersionString 用于表示一个代表版本号的字符串,支持json tag,可以直接从入参里解析
type Request struct{ AppVersion VersionString `json:"app_version"` }
注意:初始化不合法的版本号字符串,会报错。比如传递:空字符串:"",错误字符串:"2.s.3xx"
func (VersionString) EqualsTo ¶
func (v VersionString) EqualsTo(v2Str VersionString) (bool, error)
EqualsTo 当前版本号是否"等于"输入版本号
func (VersionString) GreaterOrEqualThan ¶
func (v VersionString) GreaterOrEqualThan(v2Str VersionString) (bool, error)
GreaterOrEqualThan 当前版本号是否"大于等于"输入版本号
func (VersionString) GreaterThan ¶
func (v VersionString) GreaterThan(v2Str VersionString) (bool, error)
GreaterThan 当前版本号是否"大于"输入版本号
func (VersionString) LessOrEqualThan ¶
func (v VersionString) LessOrEqualThan(v2Str VersionString) (bool, error)
LessOrEqualThan 当前版本号是否"小于等于"输入版本号
func (VersionString) LessThan ¶
func (v VersionString) LessThan(v2Str VersionString) (bool, error)
LessThan 当前版本号是否"小于"输入版本号
func (VersionString) String ¶
func (v VersionString) String() string