tool

package module
v0.0.0-...-7b1f3f9 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 25 Imported by: 0

README

go 常用的小工具

  • compress 基于 Gzip
  • convert 主要是转换一些数字与字符
  • password 基于 "golang.org/x/crypto/bcrypt" 生成密码与校验密码
  • rand 提供随机生成的数字或字符串
  • str 一些字符串处理操作
  • struct 把结构体转为map
  • time 提供时间类型, 重写了UnmarshalJSON方法,解析 null,"" 为时间时不会报错
  • uuid 提供生成UUID方法,包括(UUID, UUID去掉'-', UUID 转19位数字

Documentation

Index

Constants

View Source
const (
	// IDpool 大小
	IDpoolCount = 1000
	// 添加门槛
	AddThreshold = 300
)
View Source
const (
	//$2a$(2 chars work cost)$(22 chars salt )(31 chars hash)
	DefaultSaltLen = 29
)

Variables

This section is empty.

Functions

func BytesToInt64

func BytesToInt64(buf []byte) int64

byte 转 int64

func Compare

func Compare(encryptStr, str string) bool

Compare is to compare encryptStr and provided utils

func Compress

func Compress(data []byte) ([]byte, error)

Compress returns compressed bytes

func Decompress

func Decompress(data []byte) ([]byte, error)

Decompress returns the decompressed bytes

func FormatInt

func FormatInt(i int) string

func FormatIntv

func FormatIntv(v interface{}) string

func GenerateRandom

func GenerateRandom() uint64

generate random numbers

func GenerateUUID

func GenerateUUID() string

func GenerateUUID2Number

func GenerateUUID2Number() uint64

func GenerateUUIDWithOutLine

func GenerateUUIDWithOutLine() string

func Get

func Get(str string) (string, error)

Get returns the encrypted string for specified utils

func GetID

func GetID() snowflake.ID

func GetSalt

func GetSalt(encryptStr string) string

GetSalt returns salt from EncryptPassword

func GetTimeFromNTP

func GetTimeFromNTP() time.Time

func IntToInt64

func IntToInt64(value int) int64

int to int64

func IsNumeric

func IsNumeric(s string) bool

IsNumeric 判断锁给字符串是否为数字

func JsonString

func JsonString(v interface{}) string

func PrettyJson

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

PrettyJson returns a pretty json string

func RandString

func RandString(len int) string

Random string lowercase

func SmsContentEncode

func SmsContentEncode(signature, content string) string

GBK 编码短信内容, 需带上签名, 如果不需要签名,可以传 "" (目前只有验证码签名写死在内容中,传的签名为 "" )

func StringToInt

func StringToInt(value string) (i int)

string to int

func Stringify

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

Stringify returns a string representation

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

结构体转 map 根据 json tag, 没有就把名字 ToSnakeCase

func Structify

func Structify(data string, value interface{}) error

Structify returns the original representation

func ToInt64

func ToInt64(value interface{}) (d int64, err error)

convert any numeric value to int64 任意类型转int64

func ToSnakeCase

func ToSnakeCase(str string) string

Types

type Time

type Time time.Time

func (Time) MarshalJSON

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

func (*Time) Scan

func (t *Time) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value 和 Scan 方法用于数据库操作 implements the sql.Valuer interface

Jump to

Keyboard shortcuts

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