utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package utils *

  • @Author:manguanghui
  • @Date: 2021/11/22
  • @Desc: 生成雪花算法ID

*

Package utils *

  • @Author:manguanghui
  • @Date: 2021/11/22
  • @Desc:

*

Index

Constants

View Source
const (
	CEpoch        = 1474802888000
	CWorkerIdBits = 10 // Num of WorkerId Bits
	CSequenceBits = 12 // Num of Sequence Bits

	CWorkerIdShift  = 12
	CTimeStampShift = 22

	CSequenceMask = 0xfff // equal as getSequenceMask()
	CMaxWorker    = 0x3ff // equal as getMaxWorkerId()
)

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(str string) []byte

Base64Decode 解码

func Base64Encode

func Base64Encode(str []byte) string

Base64Encode 编码

func CreateFile

func CreateFile(filepath string)

CreateFile 创建新文件

func FileSuffix

func FileSuffix(path string) string

FileSuffix 获取文件后缀

func GeneratedID

func GeneratedID() string

GeneratedID 获取ksuid

func GetOutboundIP

func GetOutboundIP() (string, error)

GetOutboundIP 获取本地IP

func GoId

func GoId() int64

GoId 获取雪花算法ID

func IsNotString

func IsNotString(str string) bool

func IsString

func IsString(str string) bool

IsString 判断字符串是否为空

func Md5

func Md5(str string) string

Md5 @param str 字符串

func NowDate

func NowDate() string

func NowDateTime

func NowDateTime() string

NowDateTime 系统时间

func NowParseDate

func NowParseDate(date string) (time.Time, error)

func NowUnix

func NowUnix() int64

NowUnix 时间戳

func ParseId

func ParseId(id int64) (t time.Time, ts int64, workerId int64, seq int64)

ParseId Func: reverse uid to timestamp, workerId, seq

func SHA256

func SHA256(message []byte) string

SHA256 算法

func String

func String(value interface{}) string

func ZlibUnCompress

func ZlibUnCompress(compressSrc []byte) ([]byte, error)

ZlibUnCompress 解压zlib

Types

type IdWorker

type IdWorker struct {
	// contains filtered or unexported fields
}

IdWorker Struct

func NewIdWorker

func NewIdWorker(workerId int64) (iw *IdWorker, err error)

NewIdWorker Func: Generate NewIdWorker with Given workerId

func (*IdWorker) NextId

func (iw *IdWorker) NextId() (ts int64, err error)

NextId Func: Generate next id

Jump to

Keyboard shortcuts

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