base

package
v0.0.0-...-b988991 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

* @Author: calmwu * @Date: 2017-09-18 10:33:28 * @Last Modified by: calmwu * @Last Modified time: 2018-04-28 16:37:37 * @Comment:

* @Author: calmwu * @Date: 2017-09-19 16:27:11 * @Last Modified by: calmwu * @Last Modified time: 2017-09-23 11:45:05 * @Comment:

Index

Constants

View Source
const (
	SecondsPerMinute = 60
	SecondsPerHour   = 60 * 60
	SecondsPerDay    = 24 * SecondsPerHour
	SecondsPerWeek   = 7 * SecondsPerDay
)
View Source
const (
	WEBMODULE_METAS    = "ModuleMetas"
	HTTP_METHOD_GET    = 0x0001
	HTTP_METHOD_POST   = 0x0002
	HTTP_METHOD_PUT    = 0x0004
	HTTP_METHOD_DELETE = 0x0008
)
View Source
const (
	HashSeed = 0
)
View Source
const (
	KEY_BYTES_SIZE = 32
)

https://www.cnblogs.com/si812cn/archive/2009/11/26/1611272.html g是p的原根Diffie-Hellman密钥交换算法的有效性依赖于计算离散对数的难度。简言之,可以如下定义离散对数:首先定义一个素数p的原根,为其各次幂产生从1 到p-1的所有整数根,也就是说,如果a是素数p的一个原根,那么数值 a mod p, a2 mod p, ..., ap-1 mod p 是各不相同的整数,并且以某种排列方式组成了从1到p-1的所有整数。

Variables

View Source
var (
	ErrModuleKindIsNotStruct   = errors.New("Module kind is not struct")
	ErrModuleMetaInfosNotExist = errors.New("Module Interface Metainfos not exist")
	ErrModuleMetaTypeInvalid   = errors.New("Module meta type is not WebModuleInterfaceMeta")

	WebModuleInterfaceMetaType = reflect.TypeOf(c_978_WebModuleInterfaceMeta_Default)
)
View Source
var (
	GLog l4g.Logger = nil
)
View Source
var (
	SeededSecurely bool
)
View Source
var (
	ZLog *zap.SugaredLogger
)

Functions

func ArrayToString

func ArrayToString(a []int, delim string) string

func CheckDir

func CheckDir(dirPath string) error

func ConvertHashToObj

func ConvertHashToObj(m interface{}, rawVal interface{}, tagName string) error

func ConvertToFloat64

func ConvertToFloat64(i interface{}, defaultValue float64) (ret float64)

func ConvertToInt

func ConvertToInt(i interface{}, defaultValue int) int

func ConvertToInt64

func ConvertToInt64(i interface{}, defaultValue int64) (ret int64)

func ConvertToString

func ConvertToString(i interface{}, defaultValue string) (ret string)

func Crc16

func Crc16(buf string) uint16

func CreateZapLog

func CreateZapLog(logFullName string, maxSize int, maxAge int, maxBackups int, compress bool,
	logLevel zapcore.Level) *zap.SugaredLogger

logFullName: dir/dir/dir/test.log maxSize: megabytes, default = 100 maxAge: 多少天之后变为old file maxBackups: old file备份数量 compress: old file是否压缩tgz logLevel: zapcore.DebugLevel

func DecryptCipherText

func DecryptCipherText(cipherBlock cipher.Block, cipherText []byte) ([]byte, error)

in-place模式

func DumpStacks

func DumpStacks()

func EncryptPlainText

func EncryptPlainText(cipherBlock cipher.Block, plainText []byte) ([]byte, error)

传入明文,返回密文

func GenerateDHKey

func GenerateDHKey() (*dhkx.DHKey, error)

算出来的ka发送给对方

func GenerateEncryptionKey

func GenerateEncryptionKey(pub []byte, privateKey *dhkx.DHKey) ([]byte, error)

根据对方返回的kb计算加密密钥

func GetCallStack

func GetCallStack() string

func GetClientAddrFromGin

func GetClientAddrFromGin(c *gin.Context) string

func GetDate

func GetDate() string

func GetDateByLocation

func GetDateByLocation(location *time.Location) string

func GetDateHour

func GetDateHour() string

func GetDateNum

func GetDateNum(location *time.Location) int

func GetDateNum2

func GetDateNum2(now *time.Time) int

func GetDayEndTimeLocal

func GetDayEndTimeLocal() time.Time

func GetDayEndTimeUtc

func GetDayEndTimeUtc() time.Time

func GetIPByIfname

func GetIPByIfname(ifname string) (*string, error)

func GetMonthName

func GetMonthName(location *time.Location) int

func GetMonthlyDayCount

func GetMonthlyDayCount(year int, month int) int

计算某年某月的天数

func GetNextDayStartTimeByLocation

func GetNextDayStartTimeByLocation(location *time.Location) time.Time

func GetNextDayStartTimeLocal

func GetNextDayStartTimeLocal() time.Time

func GetNextDayStartTimeUtc

func GetNextDayStartTimeUtc() time.Time

func GetTimeByTz

func GetTimeByTz(tz string) (*time.Time, error)

func GetTimeStampMs

func GetTimeStampMs() string

func GetTimeStampSec

func GetTimeStampSec() string

func GetTypeName

func GetTypeName(obj interface{}) (name1, name2, name3 string)

func GetWeekDay

func GetWeekDay(location *time.Location) int32

func GetWeekName

func GetWeekName(location *time.Location) int

func GinRegisterWebModule

func GinRegisterWebModule(router *gin.Engine, webModule interface{}) error

func HashStr2Uint32

func HashStr2Uint32(s string) uint32

func HashStr2Uint64

func HashStr2Uint64(s string) uint64

func InitDefaultZapLog

func InitDefaultZapLog(logFullName string, logLevel zapcore.Level)

func InitLog

func InitLog(logFilefullPath string)

func Join

func Join(a []interface{}, sep string) string

func MapstructUnPackByJsonTag

func MapstructUnPackByJsonTag(m interface{}, rawVal interface{}) error

func MkDir

func MkDir(dirPath string) error

func NewCipherBlock

func NewCipherBlock(encryptionKey []byte) (cipher.Block, error)

func NewError

func NewError(args ...interface{}) error

func NewSimpleLog

func NewSimpleLog(out io.Writer) *log.Logger

func PathExist

func PathExist(path string) error

func PrintPerformTimeConsuming

func PrintPerformTimeConsuming(funcName string, startTime time.Time)

func RandStringBytesMaskImpr

func RandStringBytesMaskImpr(n int) string

func RandomBytes

func RandomBytes(size int) ([]byte, error)

func RandomInt

func RandomInt(n int) int

func RegisterModuleInterface

func RegisterModuleInterface(interfacePath InterfacePath, httpMethodType int, handlerFunc func(*gin.Context),
	moduleMetas WebModuleMetas)

func SeedMathRand

func SeedMathRand()

设置随机种子

func SendResponse

func SendResponse(c *gin.Context, res *ProtoResponseS)

func SendResponseToClient

func SendResponseToClient(c *gin.Context, res *ProtoResponseS)

func SetRecvBuf

func SetRecvBuf(c *net.TCPConn, recvBufSize int) error

func ShortCallerWithClassFunctionEncoder

func ShortCallerWithClassFunctionEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

func StrError

func StrError(err error) string

func TimeName

func TimeName(t time.Time) string

func ZlibCompress

func ZlibCompress(data []byte, compressLevel int) ([]byte, error)

func ZlibDCompress

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

Types

type FactoryReferenceCountable

type FactoryReferenceCountable func(ReferenceCounter) ReferenceCountable

type InterfacePath

type InterfacePath string

web模块的描述集合

type LocalizedTime

type LocalizedTime struct {
	// contains filtered or unexported fields
}
var (
	GLocalizedTime *LocalizedTime = new(LocalizedTime)
)

func (*LocalizedTime) Clock

func (this *LocalizedTime) Clock(year int, month int, day int, hour int, minute int, sec int) (time.Time, error)

根据年月日时分秒返回time结构

func (*LocalizedTime) GetLocale

func (this *LocalizedTime) GetLocale() *time.Location

获取本地区域

func (*LocalizedTime) IsCurrentWeek

func (this *LocalizedTime) IsCurrentWeek(sec int64) bool

func (*LocalizedTime) IsTheSameWeek

func (this *LocalizedTime) IsTheSameWeek(secX int64, secY int64) bool

func (*LocalizedTime) IsToday

func (this *LocalizedTime) IsToday(sec int64) bool

传入一个时间戳(秒),判断是不是今天

func (*LocalizedTime) IsYesterday

func (this *LocalizedTime) IsYesterday(sec int64) bool

传入一个时间戳(秒),判断是不是昨天

func (*LocalizedTime) NSecTimeStamp

func (this *LocalizedTime) NSecTimeStamp() int64

获取当前时间戳(纳秒)

func (*LocalizedTime) Now

func (this *LocalizedTime) Now() time.Time

获取当前时间

func (*LocalizedTime) NowDate

func (this *LocalizedTime) NowDate() (year int, month time.Month, day int)

获取当前日期(年,月,日)

func (*LocalizedTime) SecTimeStamp

func (this *LocalizedTime) SecTimeStamp() int64

获取当前时间戳(秒)

func (*LocalizedTime) SetLocale

func (this *LocalizedTime) SetLocale(loc string) error

设置本地区域,如"UTC"

func (*LocalizedTime) TodayClock

func (this *LocalizedTime) TodayClock(hour int, minute int, sec int) (time.Time, error)

根据当天的时分秒返回time结构

func (*LocalizedTime) Unix

func (this *LocalizedTime) Unix(sec int64, nsec int64) time.Time

根据给定的秒和纳秒返回time结构体(距离UTC时间1970年1月1日时间)

func (*LocalizedTime) UnixDate

func (this *LocalizedTime) UnixDate(sec int64, nsec int64) (year int, month time.Month, day int)

根据给定的秒和纳秒返回当前日期(年,月,日)

type ProtoData

type ProtoData struct {
	InterfaceName string      `json:"InterfaceName"`
	Params        interface{} `json:"Params"`
}

type ProtoFailInfoS

type ProtoFailInfoS struct {
	FailureReason string `json:"FailureReason"`
}

type ProtoRequestHeadS

type ProtoRequestHeadS struct {
	Version    int    `json:"Version"`
	EventId    int    `json:"EventId"`
	TimeStamp  int64  `json:"TimeStamp"`
	CsrfToken  string `json:"CsrfToken"`
	ChannelUID string `json:"ChannelUID"`
	Uin        int    `json:"Uin"`
}

type ProtoRequestS

type ProtoRequestS struct {
	ProtoRequestHeadS
	ReqData ProtoData `json:"ReqData"`
}

func UnpackClientRequest

func UnpackClientRequest(c *gin.Context) (*ProtoRequestS, error)

func UnpackRequest

func UnpackRequest(c *gin.Context) *ProtoRequestS

type ProtoResponseHeadS

type ProtoResponseHeadS struct {
	Version    int             `json:"Version"`
	TimeStamp  int64           `json:"TimeStamp"`
	EventId    int             `json:"EventId"`
	ReturnCode ProtoReturnCode `json:"ReturnCode"`
}

type ProtoResponseS

type ProtoResponseS struct {
	ProtoResponseHeadS
	ResData ProtoData `json:"ResData"`
}

func PostRequest

func PostRequest(url string, req *ProtoRequestS) (*ProtoResponseS, error)

type ProtoReturnCode

type ProtoReturnCode int

type ReferenceCountable

type ReferenceCountable interface {
	SetInstance(i interface{})
	IncrementReferenceCount()
	DecrementReferenceCount()
}

type ReferenceCountedPool

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

计数对象池

func NewReferenceCountedPool

func NewReferenceCountedPool(factory FactoryReferenceCountable, reset ResetReferenceCountable) *ReferenceCountedPool

生成一个计数对象池

func (*ReferenceCountedPool) Get

func (*ReferenceCountedPool) Stats

func (rcp *ReferenceCountedPool) Stats() map[string]interface{}

输出pool的统计

type ReferenceCounter

type ReferenceCounter struct {
	Instance interface{} `sql:"-" json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

计数对象类型

func (ReferenceCounter) DecrementReferenceCount

func (rc ReferenceCounter) DecrementReferenceCount()

func (ReferenceCounter) IncrementReferenceCount

func (rc ReferenceCounter) IncrementReferenceCount()

func (*ReferenceCounter) SetInstance

func (rc *ReferenceCounter) SetInstance(i interface{})

type ResetReferenceCountable

type ResetReferenceCountable func(interface{}) error

type WebItfResData

type WebItfResData struct {
	Param   interface{}
	RetCode int
}

func RequestPretreatment

func RequestPretreatment(c *gin.Context, interfaceName string, realReqPtr interface{}) (*WebItfResData, webItfResponseFunc, error)

type WebModuleInterfaceMeta

type WebModuleInterfaceMeta struct {
	HttpMethodType int
	HandlerFunc    func(*gin.Context)
}

web接口方法的描述

type WebModuleMetas

type WebModuleMetas map[InterfacePath]*WebModuleInterfaceMeta

Directories

Path Synopsis
* @Author: calmwu * @Date: 2017-11-21 14:52:04 * @Last Modified by: calmwu * @Last Modified time: 2017-11-21 17:27:18 * @Comment:
* @Author: calmwu * @Date: 2017-11-21 14:52:04 * @Last Modified by: calmwu * @Last Modified time: 2017-11-21 17:27:18 * @Comment:

Jump to

Keyboard shortcuts

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