g2util

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 40 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 ErrNotFound = errors.New("item not found")

ErrNotFound ...

View Source
var TimeNowFunc = time.Now

TimeNowFunc ...

Functions

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 CryptoRandInt added in v2.0.3

func CryptoRandInt(n int) *big.Int

CryptoRandInt ...

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 InjectPopulate

func InjectPopulate(values ...interface{})

InjectPopulate ...

func JSONDump added in v2.0.4

func JSONDump(val interface{}) string

JSONDump ...

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 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 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 ValueIndirect added in v2.0.2

func ValueIndirect(val reflect.Value) reflect.Value

ValueIndirect ...值类型

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 Config added in v2.0.3

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

Config ...

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 G2cache added in v2.0.3

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

G2cache ...

func (*G2cache) BigCache added in v2.0.3

func (g *G2cache) BigCache() *bigcache.BigCache

BigCache ...

func (*G2cache) Constructor added in v2.0.3

func (g *G2cache) Constructor()

Constructor ...

func (*G2cache) Delete added in v2.0.3

func (g *G2cache) Delete(key string) (err error)

Delete ...

func (*G2cache) Get added in v2.0.3

func (g *G2cache) Get(key string) (data []byte, err error)

Get ...

func (*G2cache) GoCache added in v2.0.3

func (g *G2cache) GoCache() *cache.Cache

GoCache ...

func (*G2cache) New added in v2.0.3

func (g *G2cache) New() *G2cache

New ...

func (*G2cache) Reset added in v2.0.3

func (g *G2cache) Reset() (err error)

Reset ...

func (*G2cache) Set added in v2.0.3

func (g *G2cache) Set(key string, data []byte) (err error)

Set ... 过期时间默认,由创建实例时指定

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 ItfCache added in v2.0.3

type ItfCache interface {
	Set(key string, data []byte) (err error)
	Get(key string) (data []byte, err error)
	Delete(key string) (err error)
	Reset() (err error)
}

ItfCache ...

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) FromDB added in v2.0.3

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

FromDB ...

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) ToDB added in v2.0.3

func (p *JSONTime) ToDB() (b []byte, err error)

ToDB ...

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 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 ... 非线程安全

Jump to

Keyboard shortcuts

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