common

package
v0.0.0-...-4b55cb2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JSONMarshal       = json.Marshal
	JSONUnmarshal     = json.Unmarshal
	JSONMarshalIndent = json.MarshalIndent
	JSONNewDecoder    = json.NewDecoder
	JSONNewEncoder    = json.NewEncoder
)

定义JSON操作

View Source
var (
	YAMLMarshal    = yaml.Marshal
	YAMLUnmarshal  = yaml.Unmarshal
	YAMLNewDecoder = yaml.NewDecoder
	YAMLNewEncoder = yaml.NewEncoder
)

定义YAML操作

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 AESDecrypt

func AESDecrypt(crypted, key []byte) []byte

解密

func AESEncrypt

func AESEncrypt(origData, key []byte) []byte

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func CheckNotExist

func CheckNotExist(src string) bool

CheckNotExist check if the file exists

func CheckPermission

func CheckPermission(src string) bool

CheckPermission check if the file has permission

func EncodeMD5

func EncodeMD5(value string) string

EncodeMD5 md5 encryption

func GetExt

func GetExt(fileName string) string

GetExt get the file ext

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize get the file size

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir create a directory if it does not exist

func IsZero

func IsZero(i ...interface{}) bool

IsZero 检查是否是零值

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON编码为字符串

func MD5Hash

func MD5Hash(b []byte) string

MD5Hash MD5哈希值

func MD5HashString

func MD5HashString(s string) string

MD5HashString MD5哈希值

func MkDir

func MkDir(src string) error

MkDir create a directory

func MustOpen

func MustOpen(fileName, filePath string) (*os.File, error)

MustOpen maximize trying to open the file

func MustUUID

func MustUUID() string

MustUUID 创建UUID,如果发生错误则抛出panic

func NewRecordID

func NewRecordID() string

NewRecordID 创建记录ID

func NewTraceID

func NewTraceID() string

NewTraceID 创建追踪ID

func NewUUID

func NewUUID() (string, error)

NewUUID 创建UUID

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open a file according to a specific mode

func PKCS7Padding

func PKCS7Padding(origData []byte, blockSize int) []byte

补码

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

去补码

func SHA1Hash

func SHA1Hash(b []byte) string

SHA1Hash SHA1哈希值

func SHA1HashString

func SHA1HashString(s string) string

SHA1HashString SHA1哈希值

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes converts string to byte slice without a memory allocation.

func StructMapToStruct

func StructMapToStruct(s, ts interface{}) error

StructMapToStruct 结构体映射

Types

type ObjectID

type ObjectID [12]byte

ObjectID is the BSON ObjectID type.

var NilObjectID ObjectID

NilObjectID is the zero value for ObjectID.

func NewObjectID

func NewObjectID() ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromTimestamp

func NewObjectIDFromTimestamp(timestamp time.Time) ObjectID

NewObjectIDFromTimestamp generates a new ObjectID based on the given time.

func ObjectIDFromHex

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

func (id ObjectID) Hex() string

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

func (ObjectID) IsZero

func (id ObjectID) IsZero() bool

IsZero returns true if id is the empty ObjectID.

func (ObjectID) MarshalJSON

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

MarshalJSON returns the ObjectID as a string

func (ObjectID) String

func (id ObjectID) String() string

func (ObjectID) Timestamp

func (id ObjectID) Timestamp() time.Time

Timestamp extracts the time part of the ObjectId.

func (*ObjectID) UnmarshalJSON

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

UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 64 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. Otherwise, it will return an error.

type S

type S string

S 字符串类型转换

func (S) Bool

func (s S) Bool() (bool, error)

Bool 转换为bool

func (S) Bytes

func (s S) Bytes() []byte

Bytes 转换为[]byte

func (S) DefaultBool

func (s S) DefaultBool(defaultVal bool) bool

DefaultBool 转换为bool,如果出现错误则使用默认值

func (S) DefaultFloat32

func (s S) DefaultFloat32(defaultVal float32) float32

DefaultFloat32 转换为float32,如果出现错误则使用默认值

func (S) DefaultFloat64

func (s S) DefaultFloat64(defaultVal float64) float64

DefaultFloat64 转换为float64,如果出现错误则使用默认值

func (S) DefaultInt

func (s S) DefaultInt(defaultVal int) int

DefaultInt 转换为int,如果出现错误则使用默认值

func (S) DefaultInt64

func (s S) DefaultInt64(defaultVal int64) int64

DefaultInt64 转换为int64,如果出现错误则使用默认值

func (S) DefaultUint

func (s S) DefaultUint(defaultVal uint) uint

DefaultUint 转换为uint,如果出现错误则使用默认值

func (S) DefaultUint64

func (s S) DefaultUint64(defaultVal uint64) uint64

DefaultUint64 转换为uint64,如果出现错误则使用默认值

func (S) Float32

func (s S) Float32() (float32, error)

Float32 转换为float32

func (S) Float64

func (s S) Float64() (float64, error)

Float64 转换为float64

func (S) Int

func (s S) Int() (int, error)

Int 转换为int

func (S) Int64

func (s S) Int64() (int64, error)

Int64 转换为int64

func (S) String

func (s S) String() string

func (S) ToJSON

func (s S) ToJSON(v interface{}) error

ToJSON 转换为JSON

func (S) Uint

func (s S) Uint() (uint, error)

Uint 转换为uint

func (S) Uint64

func (s S) Uint64() (uint64, error)

Uint64 转换为uint64

Jump to

Keyboard shortcuts

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