utils

package
v0.0.11-grpc-test Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 时间格式化字符串
	SysTimeform      string = "2006-01-02 15:04:05"
	SysTimeformShort string = "2006-01-02"
)

前面是含义,后面是 go 的表示值,多种表示,逗号","分割 年  06,2006 月份 1,01,Jan,January 日  2,02,_2 时  3,03,15,PM,pm,AM,am 分  4,04 秒  5,05 周几 Mon,Monday 时区时差表示 -07,-0700,Z0700,Z07:00,-07:00,MST 时区字母缩写 MST 您看出规律了么!哦是的,你发现了,这里面没有一个是重复的,所有的值表示都唯一对应一个时间部分。 并且涵盖了很多格式组合。

Variables

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

定义JSON操作

View Source
var SysTimeLocation, _ = time.LoadLocation("Asia/Chongqing")

中国时区

Functions

func AESDecrypt

func AESDecrypt(baseStr string) string

----------------------------------------------------------- ----------------------- 解密 ------------------------------ ----------------------------------------------------------- 先base64转码,再解密

func AESDecrypt2

func AESDecrypt2(cipherkey, ciphertext []byte) ([]byte, error)

AESDecrypt decrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func AESEncrypt

func AESEncrypt(originPWD []byte) string

----------------------------------------------------------- ----------------------- 加密 ------------------------------ ----------------------------------------------------------- 加密后再base64编码成string

func AESEncrypt2

func AESEncrypt2(cipherkey, src []byte) []byte

AESEncrypt encrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func Check

func Check(a interface{})

结构体指针检查验证,如果传入的interface为nil,就通过log.Panic函数抛出一个异常 被用在starter中检查公共资源是否被实例化了

func CheckPWD

func CheckPWD(password, enPassword string) bool

校验密码

func Config

func Config(conf interface{})

func ConfigFromFile

func ConfigFromFile(filePath string, conf interface{})

func ConfigFromSlice

func ConfigFromSlice(filePaths []string, conf interface{})

func DecimalToJsonNumber

func DecimalToJsonNumber(dd decimal.Decimal, precision int32) ejson.Number

func FileMonitoring

func FileMonitoring(filePth string, hookfn func([]byte))

文件监控

func GetActiveIps

func GetActiveIps() (ips []string, err error)

func GetCurrentPath

func GetCurrentPath(inDir string) string

获取指定相对路径的绝对路径

func GetFilesByDir

func GetFilesByDir(prefixPath string) (fileInfos []os.FileInfo, err error)

根据目录获取文件或文件夹信息,不递归获取

func GetFilesByDirFileRegex1

func GetFilesByDirFileRegex1(prefixDir string, regex string) (fileInfos []os.FileInfo, err error)

func GetLocalIps

func GetLocalIps() (ips []string, err error)

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON编码为字符串

func MapToStruct

func MapToStruct(inMap map[string]interface{}, out interface{}) error

func Md5

func Md5(b []byte) string

Md5 returns the MD5 checksum string of the data.

func PathExists

func PathExists(path string) (bool, error)

判断文件或者路径是否存在

func ProgramName added in v0.0.7

func ProgramName() string

func ReadAll

func ReadAll(filePth string) ([]byte, error)

一次性读取

func ReadBlock

func ReadBlock(filePth string, bufSize int, hookfn func([]byte)) error

分块读取 可在速度和内存占用之间取得很好的平衡。

func ReadContentByFileName

func ReadContentByFileName(fileFullName string) (fileContent []string, err error)

func ReadLine

func ReadLine(filePth string, hookfn func([]byte)) error

逐行读取

func StructToMap

func StructToMap(in interface{}) (map[string]interface{}, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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