utls

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Nanosecond  = int64(time.Nanosecond) // Nanosecond
	Microsecond = 1000 * Nanosecond      // Nanosecond
	Millisecond = 1000 * Microsecond     // Nanosecond
	Second      = 1000 * Millisecond     // Nanosecond
	Minute      = 60 * Second            // Nanosecond
	Hour        = 60 * Minute            // Nanosecond
	Day         = 24 * Hour              // Nanosecond
	Year        = 365 * Day              // Nanosecond

	SecondsPerYear   = Year / Second   // Second
	SecondsPerDay    = Day / Second    // Second
	SecondsPerHour   = Hour / Second   // Second
	SecondsPerMinute = Minute / Second // Second

	MillisecondsPerYear   = Year / Millisecond   // Millisecond
	MillisecondsPerDay    = Day / Millisecond    // Millisecond
	MillisecondsPerHour   = Hour / Millisecond   // Millisecond
	MillisecondsPerMinute = Minute / Millisecond // Millisecond
	MillisecondsPerSecond = Second / Millisecond // Millisecond

	MicrosecondsPerYear        = Year / Microsecond        // Microsecond
	MicrosecondsPerDay         = Day / Microsecond         // Microsecond
	MicrosecondsPerHour        = Hour / Microsecond        // Microsecond
	MicrosecondsPerMinute      = Minute / Microsecond      // Microsecond
	MicrosecondsPerSecond      = Second / Microsecond      // Microsecond
	MicrosecondsPerMillisecond = Millisecond / Microsecond // Microsecond
)
View Source
const MaxStatFileCount = 10
View Source
const MaxStatFileSize = 100 * 1024 * 1024
View Source
const ProfDumpBackupDir = "./prof"
View Source
const ProfDumpDir = "prof"

Variables

View Source
var TIMTOUR_Err = fmt.Errorf("insert into gouroutine pool timeout")

Functions

func Bts2Str

func Bts2Str(bts []byte) string

func CheckIfUseLCSByIdc

func CheckIfUseLCSByIdc(idc string) bool

根据idc判断是否启用LCS服务

func ConvertToInt64

func ConvertToInt64(v interface{}) (int64, error)

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. copy the file contents from src to dst.

func CpuProfiling

func CpuProfiling(s int64)

func CutStringSliceByStep

func CutStringSliceByStep(array []string, step int) (int, [][]string)

return subslice count and subslices

func DGetCurrentTime

func DGetCurrentTime(layout string) string

func DeferAppStat

func DeferAppStat(appid uint32, b time.Time, err **dogErr.CodeError)

func DeferStat

func DeferStat(b time.Time, err **dogErr.CodeError)

func Dump

func Dump(name string) (*os.File, error)

func Duration

func Duration(d int64) time.Duration

func EnsureDir

func EnsureDir(dir string) error

func Exists

func Exists(p string) bool

func FixCategoryByIdc

func FixCategoryByIdc(idc, category string) string

LCS服务为防止无法寻找到topic,需要对category添加前缀

func FormatMemStats

func FormatMemStats(m1, m2 *runtime.MemStats) string

func FromLocalDateToSecond

func FromLocalDateToSecond(v string) int64

func FromSecondToLocalDate

func FromSecondToLocalDate(v int64) string

func FromTime2TimeInt

func FromTime2TimeInt(t time.Time) int

func FuncName

func FuncName(skip int) string

func GcStats

func GcStats() string

func GetCurrentMicrosecond

func GetCurrentMicrosecond() int64

func GetCurrentMillisecond

func GetCurrentMillisecond() int64

func GetCurrentNanosecond

func GetCurrentNanosecond() int64

func GetCurrentSecond

func GetCurrentSecond() int64

func GetCurrentTime

func GetCurrentTime() string

func HumanSize

func HumanSize(s uint64) string

func Int64ArraySlice

func Int64ArraySlice(array []int64, offset int, length int) []int64

func Int64ArrayToString

func Int64ArrayToString(list []int64, sep string) string

func IsEmpty

func IsEmpty(dir string) (bool, error)
func IsLink(p string) (bool, error)

func IsSameDay

func IsSameDay(t1, t2 time.Time) bool

func IsSameDayWithTimestamp

func IsSameDayWithTimestamp(d1, d2 int64) bool

func ListDir

func ListDir(dir string) ([]string, error)

func LoadJsonToObject

func LoadJsonToObject(filename string, t interface{}) error

func Marshal

func Marshal(v interface{}) ([]byte, error)

no escape html

func MemStats

func MemStats() string

func MemStats2

func MemStats2() string

func MustFloat64

func MustFloat64(v interface{}, defaultValue float64) float64

func MustInt64

func MustInt64(v interface{}, defaultValue int64) int64

func MustInt64Array

func MustInt64Array(v interface{}, defaultValue []int64) []int64

func MustString

func MustString(v interface{}, defaultValue string) string

func MustStringArray

func MustStringArray(v interface{}, defaultValue []string) []string

func ParseMemorySize

func ParseMemorySize(size string) (uint64, error)

k, m, g

func PathExists

func PathExists(path string) bool

func RandString

func RandString(n int) string

func ReviewDumpPanic

func ReviewDumpPanic(file *os.File) error

func RuntimeStats

func RuntimeStats(d time.Duration, f func(string))

get runtime stats,contained goroutine numbers,gc pause,heap objects,heap alloc and malloc

func SafeSprintf

func SafeSprintf(format string, args ...interface{}) string

TODO://解决参数类型不对的问题,以及%.2f类似问题

func Sleep

func Sleep(millisecond int64)

func SliceCutter

func SliceCutter(v interface{}, maxsize int) ([]interface{}, error)

func SplitTimeInt

func SplitTimeInt(t int) (year, month, day int)

func Store2File

func Store2File(file string, content string) error

func Str2Bts

func Str2Bts(str string) []byte

func StringArraySlice

func StringArraySlice(array []string, offset int, length int) []string

func StringStringMap2StringInterfaceMap

func StringStringMap2StringInterfaceMap(input map[string]string) map[string]interface{}

This is a safe convert since string can always convert to interface{}

func TraceId added in v1.6.3

func TraceId() string

func TryString

func TryString(v interface{}) (string, bool)

func WithRecover

func WithRecover(fn func(), errHandler func(interface{})) (err interface{})

func WriteBlock

func WriteBlock()

func WriteGoroutine

func WriteGoroutine()

func WriteHeap

func WriteHeap()

func WriteMutex

func WriteMutex()

func WriteThreadCreate

func WriteThreadCreate()

Types

type DeployFunc

type DeployFunc func([]string) string

type FindFunc

type FindFunc func(key string) (string, error)

type FixedGoroutinePool

type FixedGoroutinePool struct {
	Size int64
	// contains filtered or unexported fields
}

func (*FixedGoroutinePool) Close

func (f *FixedGoroutinePool) Close()

func (*FixedGoroutinePool) Execute

func (f *FixedGoroutinePool) Execute(function func())

func (*FixedGoroutinePool) ExecuteWithArg

func (f *FixedGoroutinePool) ExecuteWithArg(function func(args ...interface{}), arg ...interface{})

func (*FixedGoroutinePool) Start

func (f *FixedGoroutinePool) Start() error

type FixedGoroutinePoolTimeout

type FixedGoroutinePoolTimeout struct {
	Size    int64
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*FixedGoroutinePoolTimeout) Close

func (f *FixedGoroutinePoolTimeout) Close()

func (*FixedGoroutinePoolTimeout) Execute

func (f *FixedGoroutinePoolTimeout) Execute(function func()) error

func (*FixedGoroutinePoolTimeout) Start

func (f *FixedGoroutinePoolTimeout) Start() error

type GoRoutinePoolWithConfig

type GoRoutinePoolWithConfig struct {
	DefaultSize    int64
	ReservedConfig map[string]int64
	// contains filtered or unexported fields
}

func (*GoRoutinePoolWithConfig) Close

func (g *GoRoutinePoolWithConfig) Close()

func (*GoRoutinePoolWithConfig) ExecuteDefault

func (g *GoRoutinePoolWithConfig) ExecuteDefault(function func())

func (*GoRoutinePoolWithConfig) ExecuteKey

func (g *GoRoutinePoolWithConfig) ExecuteKey(key string, function func())

func (*GoRoutinePoolWithConfig) Start

func (g *GoRoutinePoolWithConfig) Start() error

type Helper

type Helper struct {
	Host     string
	Updater  UpdateFunc
	Finder   FindFunc
	Perfer   PerfFunc
	Stater   StatusFunc
	Deployer DeployFunc
	// contains filtered or unexported fields
}

func (*Helper) Close

func (helper *Helper) Close()

func (*Helper) Start

func (helper *Helper) Start() error

type PerfFunc

type PerfFunc func() string

type Stat

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

func NewStat

func NewStat() *Stat

func (*Stat) Begin

func (st *Stat) Begin(cmd string) *Stat

func (*Stat) BeginAt

func (st *Stat) BeginAt(cmd string, begin time.Time) *Stat

BeginAt begin is micro seconds

func (*Stat) BeginFuncCmd

func (st *Stat) BeginFuncCmd() *Stat

BeginFuncCmd use funcName as cmd

func (*Stat) BeginFuncCmdAt

func (st *Stat) BeginFuncCmdAt(begin time.Time) *Stat

BeginFuncCmdAt use funcName as cmd but set begin

func (*Stat) Elapse

func (st *Stat) Elapse() time.Duration

Elapse return Duration

func (*Stat) End

func (st *Stat) End(ret int)

func (*Stat) EndErr

func (st *Stat) EndErr(err error)

type StatMgr

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

func StatMgrInstance

func StatMgrInstance() *StatMgr

func (*StatMgr) Init

func (mgr *StatMgr) Init(statPath string, statGap time.Duration)

type StatValue

type StatValue struct {
	Total  int
	SumVal int
	Avg    int64
	Max    int64
	Min    int64
	Gt10   int
	Gt100  int
	Gt500  int
	TotalD int64
}

type StatusFunc

type StatusFunc func() string

type StopableTask

type StopableTask interface {
	Close()
}

* Notice: 1. it use lock to make sure taskList is correct. performance is bad 2. still able to add task after WaitStopAll, so you should make sure no extra task is running after called WaitStopAll

type StopableTaskGroup

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

func NewStopableTaskGroup

func NewStopableTaskGroup() *StopableTaskGroup

func (*StopableTaskGroup) AddTask

func (s *StopableTaskGroup) AddTask(task StopableTask)

func (*StopableTaskGroup) Close

func (s *StopableTaskGroup) Close()

func (*StopableTaskGroup) Start

func (s *StopableTaskGroup) Start() error

func (*StopableTaskGroup) WaitStopAll

func (s *StopableTaskGroup) WaitStopAll()

type UpdateFunc

type UpdateFunc func(Key, Value, Type string, Offset int64) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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