g2util

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TimeZone ...
	TimeZone = "Asia/Shanghai"
	//Custom ...
	Custom = "2006-01-02 15:04:05"
	//DateLayout ...
	DateLayout = "2006-01-02"
)
View Source
const (
	MB int
)

常量,大小定义

Variables

View Source
var TimeNowFunc = time.Now

TimeNowFunc ...

View Source
var Valid = new(Validator).New()

Valid ...

Functions

func CheckPassword added in v2.2.1

func CheckPassword(p, c string) error

CheckPassword ...

func CopyBean added in v2.0.4

func CopyBean(bean interface{}) (newBean interface{}, err error)

CopyBean ... *

  • @Description: copy原始数据到新数据
  • @param bean
  • @return newBean
  • @return err

func CryptKey added in v2.2.1

func CryptKey() string

CryptKey ...

func CryptoRandInt added in v2.0.3

func CryptoRandInt(n int) *big.Int

CryptoRandInt ...

func DecryptPassword added in v2.2.1

func DecryptPassword(p string) (s string, err error)

DecryptPassword ...

func EncryptPassword added in v2.2.1

func EncryptPassword(p string) string

EncryptPassword ...

func FileAbsPath added in v2.0.2

func FileAbsPath(path string) string

FileAbsPath ...

func FindPidSliceByProcessName added in v2.0.3

func FindPidSliceByProcessName(name string) []string

FindPidSliceByProcessName get pid list

func FloatPrecision added in v2.2.1

func FloatPrecision(f *float64, p int) float64

FloatPrecision 浮点型精度包装

func InjectPopulate

func InjectPopulate(values ...interface{})

InjectPopulate ...

func JSONDump added in v2.0.4

func JSONDump(val interface{}, args ...interface{}) string

JSONDump ...

func JSONMarshalToBase64 added in v2.2.1

func JSONMarshalToBase64(val interface{}) ([]byte, error)

JSONMarshalToBase64 ...

func JSONUnmarshalFromBase64 added in v2.2.1

func JSONUnmarshalFromBase64(data []byte, val interface{}) error

JSONUnmarshalFromBase64 ...

func JsMarshal added in v2.2.1

func JsMarshal(val interface{}) (bts []byte)

JsMarshal ...

func JsMarshalIndent added in v2.2.1

func JsMarshalIndent(val interface{}) (bts []byte)

JsMarshalIndent ...

func KillProcess added in v2.0.3

func KillProcess(name string) (err error)

KillProcess ...kill process

func MathRandInt added in v2.0.3

func MathRandInt(n int) int

MathRandInt ...

func MergeBean added in v2.2.1

func MergeBean(dst interface{}, src Map) (err error)

MergeBean ... @Description: merge struct's point, merge src to dst @param dst @param src

func MergeBeans added in v2.0.4

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

MergeBeans ... 合并结构数据

func NewValue added in v2.0.3

func NewValue(bean interface{}) (val interface{})

NewValue ...

func ObjectTagInstances added in v2.0.4

func ObjectTagInstances(obj interface{}, tagName string) []interface{}

ObjectTagInstances ... *

  • @Description:根据标签获取字段实例集合
  • @param obj
  • @param tagName
  • @return []interface{}

func ProcessIsRunning added in v2.0.3

func ProcessIsRunning(name string) bool

ProcessIsRunning is running

func RandUseragent added in v2.0.3

func RandUseragent() string

RandUseragent ...

func RetryDo added in v2.0.3

func RetryDo(fn func() error, intervalSecond int64) error

RetryDo 重试行为

func RetryDoTimes added in v2.0.3

func RetryDoTimes(times, intervalSecond int64, fn func() error) error

RetryDoTimes ...

func SetTimeZone added in v2.0.3

func SetTimeZone() error

SetTimeZone ...Shanghai

func ShortUUID added in v2.2.1

func ShortUUID() string

ShortUUID ...

func TextTemplateMustParse added in v2.0.2

func TextTemplateMustParse(text string, data interface{}) (result string)

TextTemplateMustParse ...

func Ticker added in v2.0.3

func Ticker(d time.Duration, fn func())

Ticker ...

func TimeExcWrap added in v2.0.3

func TimeExcWrap(fn func()) time.Duration

TimeExcWrap 包装执行时间

func TimeNow added in v2.0.3

func TimeNow() time.Time

TimeNow ...

func TodayDate added in v2.0.3

func TodayDate() string

TodayDate ...

func TranslateSlice2Interfaces added in v2.2.1

func TranslateSlice2Interfaces(sl interface{}) []interface{}

TranslateSlice2Interfaces ...

func UUIDString added in v2.2.1

func UUIDString() string

UUIDString ...

func ValueIndirect added in v2.0.2

func ValueIndirect(val reflect.Value) reflect.Value

ValueIndirect ...值类型

func Write2file added in v2.2.1

func Write2file(fileName, content string)

Write2file ...

Types

type ABFileOption added in v2.0.3

type ABFileOption struct {
	//文件最大值,超过该值自动备份,备份文件大小略大于该值
	FileMaxSize int
	//保存目录天数
	SaveDays int
	//writer buffer size,内存缓冲区大小
	BufferSize int
	//自动刷新数据到磁盘的周期,默认值为2秒
	AutoFlushPeriod time.Duration
	//检查删除过期文件目录间隔
	AutoDelPeriod time.Duration
}

ABFileOption 参数配置

type AbFile added in v2.0.3

type AbFile struct {
	Config   *Config   `inject:""`
	Graceful *Graceful `inject:""`
	// contains filtered or unexported fields
}

AbFile ...

func (*AbFile) Constructor added in v2.0.3

func (a *AbFile) Constructor()

Constructor ...

func (*AbFile) MustLogIO added in v2.0.3

func (a *AbFile) MustLogIO(name string) IWriter

MustLogIO ...

func (*AbFile) MustNewIO added in v2.0.3

func (a *AbFile) MustNewIO(filePath string, opts ...*ABFileOption) IWriter

MustNewIO ...获取一个io对象,一旦出错,将会panic

type Captcha added in v2.2.1

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

Captcha ...

func (*Captcha) Cap added in v2.2.1

func (c *Captcha) Cap() *base64Captcha.Captcha

Cap ...

func (*Captcha) Constructor added in v2.2.1

func (c *Captcha) Constructor()

Constructor ...

func (*Captcha) Generate added in v2.2.1

func (c *Captcha) Generate() (id, b64s string, err error)

Generate ...

func (*Captcha) SetCap added in v2.2.1

func (c *Captcha) SetCap(cap *base64Captcha.Captcha)

SetCap ...

func (*Captcha) Verify added in v2.2.1

func (c *Captcha) Verify(id, answer string) (match bool)

Verify ...

type Config added in v2.0.3

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

Config ...

func (*Config) AppName added in v2.2.1

func (c *Config) AppName() string

AppName ...

func (*Config) Constructor added in v2.0.3

func (c *Config) Constructor()

Constructor ...初始化

func (*Config) Load added in v2.0.3

func (c *Config) Load(args ...interface{})

Load ...

func (*Config) RootPath added in v2.0.3

func (c *Config) RootPath() string

RootPath ...

func (*Config) SetFilename added in v2.0.3

func (c *Config) SetFilename(filename string)

SetFilename ...

func (*Config) SetRootPath added in v2.0.3

func (c *Config) SetRootPath(rootPath string)

SetRootPath ...

func (*Config) Viper added in v2.0.3

func (c *Config) Viper() *viper.Viper

Viper ...

type Crypto added in v2.2.1

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

Crypto ...

func NewCrypto added in v2.2.1

func NewCrypto(key string) *Crypto

NewCrypto ...

func (*Crypto) Decrypt added in v2.2.1

func (c *Crypto) Decrypt(ciphertext string) (string, error)

Decrypt ...

func (*Crypto) DecryptCBC added in v2.2.1

func (c *Crypto) DecryptCBC(ciphertext string) (string, error)

DecryptCBC ...

func (*Crypto) Encrypt added in v2.2.1

func (c *Crypto) Encrypt(val string) string

Encrypt ...

func (*Crypto) EncryptCBC added in v2.2.1

func (c *Crypto) EncryptCBC(val string) string

EncryptCBC ...

func (*Crypto) Key added in v2.2.1

func (c *Crypto) Key() string

Key ...

type G2cron added in v2.0.3

type G2cron struct {
	Logger LevelLogger `inject:""`
	// contains filtered or unexported fields
}

G2cron ...

func (*G2cron) AddTask added in v2.0.3

func (c *G2cron) AddTask(spec string, fn func())

AddTask ...

func (*G2cron) Constructor added in v2.0.3

func (c *G2cron) Constructor()

Constructor ...

func (*G2cron) Cron added in v2.0.3

func (c *G2cron) Cron() *cron.Cron

Cron ...

func (*G2cron) OnProcessStart added in v2.0.3

func (c *G2cron) OnProcessStart()

OnProcessStart ...启动定时任务

type GoPool added in v2.0.3

type GoPool struct {
	LevelLogger LevelLogger `inject:""`
	Grace       *Graceful   `inject:""`
	// contains filtered or unexported fields
}

GoPool ...goroutine pool

func (*GoPool) AfterShutdown added in v2.0.3

func (g *GoPool) AfterShutdown()

AfterShutdown ...

func (*GoPool) Constructor added in v2.0.3

func (g *GoPool) Constructor()

Constructor ...

func (*GoPool) Go added in v2.0.3

func (g *GoPool) Go(fn goFunc)

Go ... 直接执行,不加入wait队列

func (*GoPool) Pool added in v2.0.3

func (g *GoPool) Pool() *ants.Pool

Pool ...

func (*GoPool) Submit added in v2.0.3

func (g *GoPool) Submit(fn goFunc)

Submit ...

type Graceful added in v2.0.3

type Graceful struct {
	Logger LevelLogger `inject:""`
	// contains filtered or unexported fields
}

Graceful ...

func (*Graceful) Constructor added in v2.0.3

func (g *Graceful) Constructor()

Constructor ...

func (*Graceful) RegHTTPServer added in v2.0.3

func (g *Graceful) RegHTTPServer(srv *http.Server)

RegHTTPServer ...注册一个http服务

func (*Graceful) RegProcessor added in v2.0.3

func (g *Graceful) RegProcessor(p ItfGracefulProcess)

RegProcessor ...注册一个对象,用于关闭程序后的行为

func (*Graceful) StartSignal added in v2.0.3

func (g *Graceful) StartSignal()

StartSignal ...监听信号

func (*Graceful) WaitForSignal added in v2.0.3

func (g *Graceful) WaitForSignal()

WaitForSignal ...

type IWriter added in v2.0.3

type IWriter interface {
	AfterShutdown()
	Closed() bool
	Close()
	Flush() (err error)
	Write(p []byte) (n int, err error)
	File() *os.File
}

IWriter ...

type ItfExec added in v2.0.3

type ItfExec interface {
	Start() error
	Run() error
	Output() ([]byte, error)
	CombinedOutput() ([]byte, error)
}

ItfExec ...

func NewExecInner added in v2.0.3

func NewExecInner(s string, out io.Writer) ItfExec

NewExecInner ...

func StdExec added in v2.0.3

func StdExec(s string) ItfExec

StdExec ...

type ItfGracefulProcess added in v2.0.3

type ItfGracefulProcess interface{ AfterShutdown() }

ItfGracefulProcess 接口,提供给关闭后行为

type JSONTime added in v2.0.3

type JSONTime time.Time

JSONTime ...

func Must2JSONTimeAddr added in v2.0.3

func Must2JSONTimeAddr(in string) *JSONTime

Must2JSONTimeAddr maybe panic

func NewJSONTimeOfTime added in v2.0.3

func NewJSONTimeOfTime(t time.Time) *JSONTime

NewJSONTimeOfTime 时间转换为JSONTime

func Now added in v2.0.3

func Now() *JSONTime

Now 当前时间

func ToDatetime added in v2.0.3

func ToDatetime(in string) (JSONTime, error)

ToDatetime ...

func Today added in v2.0.3

func Today() *JSONTime

Today ...今日日期

func (*JSONTime) Add added in v2.0.3

func (p *JSONTime) Add(d time.Duration) *JSONTime

Add ...

func (JSONTime) Addr added in v2.0.3

func (p JSONTime) Addr() *JSONTime

Addr ...

func (*JSONTime) Convert2Time added in v2.0.3

func (p *JSONTime) Convert2Time() time.Time

Convert2Time ...

func (*JSONTime) Date added in v2.0.3

func (p *JSONTime) Date() *JSONTime

Date ...返回一个日期0点的时间

func (*JSONTime) GobDecode added in v2.0.3

func (p *JSONTime) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface.

func (*JSONTime) GobEncode added in v2.0.3

func (p *JSONTime) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface.

func (*JSONTime) MarshalJSON added in v2.0.3

func (p *JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*JSONTime) Scan added in v2.0.3

func (p *JSONTime) Scan(v interface{}) error

Scan valueof time.Time

func (*JSONTime) SetByTime added in v2.0.3

func (p *JSONTime) SetByTime(timeVal time.Time)

SetByTime ...

func (*JSONTime) String added in v2.0.3

func (p *JSONTime) String() string

String ...

func (*JSONTime) StringFormat added in v2.0.3

func (p *JSONTime) StringFormat(layout string) string

StringFormat 转换为固定格式字符串

func (*JSONTime) Time added in v2.0.3

func (p *JSONTime) Time() time.Time

Time ...

func (*JSONTime) UnmarshalJSON added in v2.0.3

func (p *JSONTime) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

func (*JSONTime) Value added in v2.0.3

func (p *JSONTime) Value() (driver.Value, error)

Value insert timestamp into Mysql need this function.

type Level added in v2.0.3

type Level uint32

Level type

const (
	PanicLevel Level = iota
	FatalLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

level

func ParseLevel added in v2.0.3

func ParseLevel(lvl string) Level

ParseLevel takes a string level and returns the log level constant.

func (Level) MarshalText added in v2.0.3

func (level Level) MarshalText() ([]byte, error)

MarshalText ...

func (Level) String added in v2.0.3

func (level Level) String() string

Convert the Level to a string. E.g. PanicLevel becomes "panic".

func (*Level) UnmarshalText added in v2.0.3

func (level *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type LevelLogger added in v2.0.3

type LevelLogger interface {
	SetOutput(io.Writer)
	Writer() io.Writer

	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})

	Fatal(...interface{})
	Fatalf(string, ...interface{})
	Fatalln(...interface{})

	Panic(...interface{})
	Panicf(string, ...interface{})
	Panicln(...interface{})

	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})

	SetLevel(lvl Level)
}

LevelLogger ...

func NewLevelLogger added in v2.0.3

func NewLevelLogger(prefix string, out ...io.Writer) LevelLogger

NewLevelLogger ...

type Map added in v2.0.2

type Map map[string]interface{}

Map ...

func Bean2Map added in v2.0.2

func Bean2Map(bean interface{}) (Map, error)

Bean2Map ...

func (Map) GetBool added in v2.0.2

func (m Map) GetBool(key string) bool

GetBool ...

func (Map) GetInt added in v2.0.2

func (m Map) GetInt(key string) int

GetInt ...

func (Map) GetInt64 added in v2.0.2

func (m Map) GetInt64(key string) int64

GetInt64 ...

func (Map) GetString added in v2.0.2

func (m Map) GetString(key string) string

GetString ...

func (Map) Keys added in v2.0.7

func (m Map) Keys() []string

Keys ...

func (Map) MarshalBinary added in v2.0.2

func (m Map) MarshalBinary() (data []byte, err error)

MarshalBinary ...

func (Map) Merge2Bean added in v2.0.4

func (m Map) Merge2Bean(bean interface{}) (err error)

Merge2Bean ...

func (Map) MergeTo added in v2.0.2

func (m Map) MergeTo(mp Map)

MergeTo ...

func (Map) ToBean added in v2.0.2

func (m Map) ToBean(bean interface{}) (err error)

ToBean ...

func (*Map) UnmarshalBinary added in v2.0.2

func (m *Map) UnmarshalBinary(data []byte) error

UnmarshalBinary ...

type MapString added in v2.2.1

type MapString map[string]string

MapString ...

func (MapString) TransMapStringToMap added in v2.2.1

func (m MapString) TransMapStringToMap() Map

TransMapStringToMap ...

type RestyAgent added in v2.0.3

type RestyAgent struct {
	Logger LevelLogger `inject:""`
	// contains filtered or unexported fields
}

RestyAgent ...

func (*RestyAgent) Client added in v2.0.3

func (a *RestyAgent) Client() *resty.Client

Client ...

func (*RestyAgent) Constructor added in v2.0.3

func (a *RestyAgent) Constructor()

Constructor ...

func (*RestyAgent) New added in v2.0.3

func (a *RestyAgent) New() *RestyAgent

New ...

func (*RestyAgent) SetDialTimeout added in v2.0.3

func (a *RestyAgent) SetDialTimeout(d time.Duration) *RestyAgent

SetDialTimeout ... 非线程安全

func (*RestyAgent) SetProxy added in v2.0.3

func (a *RestyAgent) SetProxy(proxyURL string, user *url.Userinfo) *RestyAgent

SetProxy ... 非线程安全

type Validator added in v2.2.1

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

Validator ...

func (*Validator) Constructor added in v2.2.1

func (v *Validator) Constructor()

Constructor ...

func (*Validator) New added in v2.2.1

func (v *Validator) New() *Validator

New ...

func (*Validator) TranslateZh added in v2.2.1

func (v *Validator) TranslateZh(es error) (err error)

TranslateZh ...

func (*Validator) Valid added in v2.2.1

func (v *Validator) Valid() *validator.Validate

Valid ...

func (*Validator) ValidAndTranslateZh added in v2.2.1

func (v *Validator) ValidAndTranslateZh(s interface{}) (err error)

ValidAndTranslateZh ...

func (*Validator) ValidVarWithTransZh added in v2.2.1

func (v *Validator) ValidVarWithTransZh(val interface{}, tag string) (err error)

ValidVarWithTransZh ...

Jump to

Keyboard shortcuts

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