common

package
v0.0.0-...-7206171 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MulanPSL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const CodeOk = "00000"

CodeOk 一切OK的CODE

View Source
const CodeRpcFail = "B0001"

CodeRpcFail rpc调用异常

View Source
const Day1Second = Hour1Second * 24

Day1Second one day second

View Source
const Day30Second = Day1Second * 30

Day30Second 30 day second

View Source
const Day3Second = Day1Second * 3

Day3Second three day second

View Source
const Day7Second = Day1Second * 7

Day7Second seven day second

View Source
const DbCacheModeAll = "data/cache"

DbCacheModeAll 数据库缓存模式-全部

View Source
const DbCacheModeCacheFirst = "cache"

DbCacheModeCacheFirst 数据库缓存模式-缓存

View Source
const DbDataUpdateQueue = "Cache:Update:"

DbDataUpdateQueue 数据更新队列名

View Source
const Hour1Second = Minute1Second * 60

Hour1Second one hour second

View Source
const Hour30Second = Hour1Second * 30

Hour30Second 30 hour second

View Source
const Minute15Second = Minute1Second * 15

Minute15Second 15 minute second

View Source
const Minute1Second = 60

Minute1Second one minute second

View Source
const MsgOk = "ok"

MsgOk 一切OK的消息

View Source
const RetOk = "0"

RetOk 一切OK的返回码

View Source
const RetSystemFail = "500"

RetSystemFail 系统错误的返回码

View Source
const TimeDayFormat = "2006-01-02"
View Source
const TimeFormat = "2006-01-02 15:04:05"
View Source
const TimeMonthFormat = "2006-01"

Variables

View Source
var SelfRuntime = NewRuntimes()
View Source
var Snow = &SnowFlake{
	lastTime: time.Now().UnixNano() / 1000000,
}

Functions

func ConvertJson

func ConvertJson(data interface{}) string

func ConvertResult

func ConvertResult(result *LResult) string

func GetLock

func GetLock(ids ...string) bool

func Lock

func Lock(ids ...string)

func ParseJson

func ParseJson(str string, data interface{}) interface{}

func RedisGetLock

func RedisGetLock(res string, goId uint64) bool

func RedisLock

func RedisLock(res string, goId uint64)

func RedisUnlock

func RedisUnlock(res string, goId uint64)

func SimpleCopyProperties

func SimpleCopyProperties(dst, src interface{}) (err error)

func TestFail

func TestFail(lResult *LResult) bool

func Unlock

func Unlock(ids ...string)

func UnlockAll

func UnlockAll()

Types

type LResult

type LResult struct {
	Api     string      `json:"api,omitempty"`
	Code    string      `json:"code,omitempty"`
	ErrCode string      `json:"err_code,omitempty"`
	Msg     string      `json:"msg,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

func GenFailData

func GenFailData(code string, errCode string, msg string, data interface{}) *LResult

func GenOkData

func GenOkData(data interface{}) *LResult

func OfFail

func OfFail(code string, errCode string, msg string) *LResult

func OfFailData

func OfFailData(code string, errCode string, msg string, data interface{}) *LResult

func OfOkData

func OfOkData(data interface{}) *LResult

func Ok

func Ok() *LResult

type ProtocolType

type ProtocolType string
const (
	ProtocolProtobuf ProtocolType = "proto"
	ProtocolJson     ProtocolType = "json"
)

func (ProtocolType) String

func (p ProtocolType) String() string

func (ProtocolType) ValueOf

func (p ProtocolType) ValueOf(value string) ProtocolType

type Runtimes

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

func NewRuntimes

func NewRuntimes() *Runtimes

func (Runtimes) GetCache

func (r Runtimes) GetCache(name string, original func() string) string

func (*Runtimes) GoId

func (*Runtimes) GoId() uint64

type SnowFlake

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

func (*SnowFlake) GetMachineId

func (c *SnowFlake) GetMachineId() int64

GetMachineId 获取机器id

func (*SnowFlake) GetSnowflakeId

func (c *SnowFlake) GetSnowflakeId() (id, ts int64)

GetSnowflakeId 获取雪花 返回值 id:自增id ts:生成该id的毫秒时间戳

func (*SnowFlake) GetSnowflakeIdStr

func (c *SnowFlake) GetSnowflakeIdStr() string

func (*SnowFlake) MilliSecondToTime

func (c *SnowFlake) MilliSecondToTime(milliSecond int64) (t time.Time)

MilliSecondToTime 毫秒转换成time

func (*SnowFlake) MillisecondToTimeDb

func (c *SnowFlake) MillisecondToTimeDb(ts int64) string

MillisecondToTimeDb 毫秒转换成"2006-01-02 15:04:05.999"

func (*SnowFlake) MillisecondToTimeTz

func (c *SnowFlake) MillisecondToTimeTz(ts int64) string

MillisecondToTimeTz 毫秒转换成"20060102T150405.999Z"

func (*SnowFlake) ParseId

func (c *SnowFlake) ParseId(id int64) (milliSecond, mId, sn int64)

ParseId 解析雪花(id) 返回值 milliSecond:毫秒数 mId:机器id sn:序列号

func (*SnowFlake) SetMachineId

func (c *SnowFlake) SetMachineId(mId int64)

SetMachineId 设置机器id,默认为0,范围[0,255]

Jump to

Keyboard shortcuts

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