utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: GPL-3.0 Imports: 31 Imported by: 8

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 DisableCache bool

DisableCache will disable caching of the home directory. Caching is enabled by default.

Functions

func Abs

func Abs(x int) int

func AnyToAny

func AnyToAny(src interface{}, des interface{}) error

func Base64Dec

func Base64Dec(encodeString string) string

Base64Dec base64解码

func Base64DecUrl

func Base64DecUrl(encodeString string) string

Base64DecUrl base64 URL解码

func Base64Enc

func Base64Enc(input []byte) string

Base64Enc base64编码

func Base64EncUrl

func Base64EncUrl(input []byte) string

Base64EncUrl base64 URL编码

func Black

func Black(str string, modifier ...interface{}) string

黑色

func Blue

func Blue(str string, modifier ...interface{}) string

蓝色

func Brown

func Brown(str string, modifier ...interface{}) string

棕色

func CheckEmail

func CheckEmail(email string) error

CheckEmail will check a email is valid

func CurrentUTCTime

func CurrentUTCTime() string

func Cyan

func Cyan(str string, modifier ...interface{}) string

青色/蓝绿色

func DarkGray

func DarkGray(str string, modifier ...interface{}) string

深灰色

func Decrypt3DES

func Decrypt3DES(src, private []byte) []byte

Decrypt3DES 使用des进行解密

func DecryptAES

func DecryptAES(src, private []byte) []byte

DecryptAES 使用AES解密

func DecryptDES

func DecryptDES(src, private []byte) []byte

DecryptDES 使用des进行解密

func Difference

func Difference(slice1, slice2 []string) []string

求差集 slice1-并集

func Dir

func Dir() (string, error)

Dir returns the home directory for the executing user.

This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.

func Encrypt3DES

func Encrypt3DES(src []byte, private []byte) []byte

Encrypt3DES 使用des进行对称加密 length 24

func EncryptAES

func EncryptAES(src, private []byte) []byte

EncryptAES 使用AES加密 length 16

func EncryptDES

func EncryptDES(src []byte, private []byte) []byte

EncryptDES 使用des进行对称加密 length 8

func EnsureDirExist

func EnsureDirExist(name string) error

func Expand

func Expand(path string) (string, error)

Expand expands the path to include the home directory if the path is prefixed with `~`. If it isn't prefixed with `~`, the path is returned as-is.

func FileExists

func FileExists(name string) bool

func GetMapDefault

func GetMapDefault(k, defaultValue interface{}, m map[interface{}]interface{}) interface{}

func GetRandomString

func GetRandomString(length int) string

func Green

func Green(str string, modifier ...interface{}) string

绿色字体,modifier里,第一个控制闪烁,第二个控制下划线

func GzipCompressFile

func GzipCompressFile(srcPath, dstPath string) error

func In

func In(haystack interface{}, needle interface{}) (bool, error)

In example: r, err := In([]interface{}{1, "two", 3}, "two")

func InIntSliceMapKeyFunc

func InIntSliceMapKeyFunc(haystack []int) func(int) bool

func InOfInt

func InOfInt(obj int, arrayList []int) bool

func InOfInt32

func InOfInt32(obj int32, arrayList []int32) bool

func InOfInt64

func InOfInt64(obj int64, arrayList []int64) bool

func InOfStr

func InOfStr(str string, arrayList []string) bool

func InOfType

func InOfType(obj interface{}, arrayList []interface{}, dataType string) bool

func Intersect

func Intersect(slice1, slice2 []string) []string

求交集

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON编码为字符串

func LightBlue

func LightBlue(str string, modifier ...interface{}) string

淡蓝

func LightCyan

func LightCyan(str string, modifier ...interface{}) string

淡青色

func LightGray

func LightGray(str string, modifier ...interface{}) string

浅灰色

func LightGreen

func LightGreen(str string, modifier ...interface{}) string

淡绿

func LightPurple

func LightPurple(str string, modifier ...interface{}) string

淡紫色

func LightRed

func LightRed(str string, modifier ...interface{}) string

淡红色

func MD5Hash

func MD5Hash(b []byte) string

MD5Hash MD5哈希值

func MD5HashString

func MD5HashString(s string) string

MD5HashString MD5哈希值 返回一个32位md5加密后的字符串

func MD5HashString16

func MD5HashString16(data string) string

MD5HashString16 返回一个16位md5加密后的字符串

func Marshal

func Marshal(v interface{}) (string, error)

ToJSON 转换为JSON Json Marshal:将数据编码成json字符串

func Pop

func Pop(haystack interface{}, needle interface{}) (bool, error)

func PrettyJson

func PrettyJson(data interface{}) (string, error)

func Purple

func Purple(str string, modifier ...interface{}) string

紫色

func RandString

func RandString(len int) string

func Red

func Red(str string, modifier ...interface{}) string

红字体

func Reset

func Reset()

Reset clears the cache, forcing the next call to Dir to re-detect the home directory. This generally never has to be called, but can be useful in tests if you're modifying the home directory via the HOME env var or something.

func SHA1Hash

func SHA1Hash(b []byte) string

SHA1Hash SHA1哈希值

func SHA1HashString

func SHA1HashString(s string) string

SHA1HashString SHA1哈希值

func SHA256Hash

func SHA256Hash(b []byte) string

SHA256Hash SHA256哈希值

func SHA256HashString

func SHA256HashString(s string) string

SHA256HashString SHA1哈希值

func SortInIntSlice

func SortInIntSlice(haystack []int, needle int) bool

二分查找

func Sum

func Sum(i []int) int

func TestAll

func TestAll()

func Union

func Union(slice1, slice2 []string) []string

求并集

func Unmarshal

func Unmarshal(s string, v interface{}) error

ToStruct 转换为Struct Json Unmarshal:将json字符串解码到相应的数据结构

func White

func White(str string, modifier ...interface{}) string

白色

func Yellow

func Yellow(str string, modifier ...interface{}) string

黄色字体

Types

type Hash

type Hash struct{}

func (*Hash) MD5HashString

func (h *Hash) MD5HashString(s string) string

MD5HashString MD5哈希值

func (*Hash) SHA1HashString

func (h *Hash) SHA1HashString(s string) string

func (*Hash) SHA256HashString

func (h *Hash) SHA256HashString(s string) string

type IHash

type IHash interface {
	MD5HashString(s string) string
	SHA1HashString(s string) string
	SHA256HashString(s string) string
}

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) JsonToString

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

func (S) String

func (s S) String() string

func (S) Uint

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

Uint 转换为uint

func (S) Uint64

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

Uint64 转换为uint64

type UUID

type UUID [16]byte

A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC 4122.

var Nil UUID

Nil empty UUID, all zeros

func Must

func Must(uuid UUID, err error) UUID

Must returns uuid if err is nil and panics otherwise.

func NewHash

func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID

NewHash returns a new UUID derived from the hash of space concatenated with data generated by h. The hash should be at least 16 byte in length. The first 16 bytes of the hash are used to form the UUID. The version of the UUID will be the lower 4 bits of version.

func NewMD5

func NewMD5(space UUID, data []byte) UUID

NewMD5 returns a new MD5 (Version 3) UUID based on the supplied name space and data. It is the same as calling:

NewHash(md5.New(), space, data, 3)

func NewRandom

func NewRandom() (UUID, error)

NewRandom returns a Random (Version 4) UUID.

The strength of the UUIDs is based on the strength of the crypto/rand package.

A note about uniqueness derived from the UUID Wikipedia entry:

Randomly generated UUIDs have 122 random bits.  One's annual risk of being
hit by a meteorite is estimated to be one chance in 17 billion, that
means the probability is about 0.00000000006 (6 × 10−11),
equivalent to the odds of creating a few tens of trillions of UUIDs in a
year and having one duplicate.

func NewSHA1

func NewSHA1(space UUID, data []byte) UUID

NewSHA1 returns a new SHA1 (Version 5) UUID based on the supplied name space and data. It is the same as calling:

NewHash(sha1.New(), space, data, 5)

func (UUID) Bytes

func (uuid UUID) Bytes() []byte

Bytes returns bytes slice representation of UUID.

func (UUID) String

func (uuid UUID) String() string

String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.

Jump to

Keyboard shortcuts

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