goutils

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 24 Imported by: 55

README

goutils

utils for golang

JSON

Documentation

Overview

Package sgc7utils is a generated GoMock package.

Index

Constants

View Source
const RuneStr = "0"
View Source
const Version = "v0.2.2"

Version -

Variables

View Source
var (
	// ErrInvalidArrayLength - invalid array length
	ErrInvalidArrayLength = errors.New("invalid array length")
	// ErrInvalidJsonString - invalid json string
	ErrInvalidJsonString = errors.New("invalid json string")
	// ErrInvalidJsonInt - invalid json int
	ErrInvalidJsonInt = errors.New("invalid json int")
	// ErrInvalidJsonBool - invalid json bool
	ErrInvalidJsonBool = errors.New("invalid json bool")
	// ErrInvalidVersion - invalid Version
	ErrInvalidVersion = errors.New("invalid Version")
	// ErrDuplicateMsgCtx - duplicate msg ctx
	ErrDuplicateMsgCtx = errors.New("duplicate msg ctx")
	// ErrNoMsgCtx - no msg ctx
	ErrNoMsgCtx = errors.New("no msg ctx")
	// ErrInvalidMsgName - invalid MsgName
	ErrInvalidMsgName = errors.New("invalid MsgName")
	// ErrNoMsgName - no MsgName
	ErrNoMsgName = errors.New("no MsgName")

	// ErrInvalidNameInMapWeights - invalid Name in MapWeights
	ErrInvalidNameInMapWeights = errors.New("invalid Name in MapWeights")
)
View Source
var FloatPrecision float64 = 0.00000001

Functions

func AppendString

func AppendString(strs ...string) string

AppendString - append string

func BuildVersionFile added in v0.1.22

func BuildVersionFile(fn string, tmpfn string, vobj *VersionObj) error

func CloneArr3 added in v0.1.2

func CloneArr3(src [][][]int) [][][]int

CloneArr3 - clone a [][][]int

func CloneIntArr added in v0.1.49

func CloneIntArr(arr []int) []int

CloneIntArr - clone a []int

func CloneIntArr2

func CloneIntArr2(arr [][]int) [][]int

CloneIntArr2 - clone a [][]int

func Debug

func Debug(message string, fields ...slog.Attr)

Debug logs a debug message with the given fields

func Err added in v0.2.2

func Err(err error) slog.Attr

func Error

func Error(message string, fields ...slog.Attr)

Error logs a debug message with the given fields

func FindInt added in v0.1.2

func FindInt(arr []int, val int) int

FindInt - find a int into []int

func FindInt3 added in v0.1.2

func FindInt3(arr []int, x, y, z int) int

FindInt3 - find 3 ints into []int

func FindIntArr added in v0.1.2

func FindIntArr(arr [][]int, vals []int) int

FindIntArr - find a int array into [][]int

func FlipIntArr2

func FlipIntArr2(arr [][]int) [][]int

FlipIntArr2 - arr[x][y] -> arr[y][x]

func FormatNow

func FormatNow(t ITime) string

FormatNow - format time

func FormatUTCDayTs added in v0.1.15

func FormatUTCDayTs(t time.Time) int64

func GenHashCode added in v0.1.2

func GenHashCode(length int) string

GenHashCode - generator a hash code

func GetCurTimestamp added in v0.1.3

func GetCurTimestamp() int64

func GetJsonArrayEachInt added in v0.1.10

func GetJsonArrayEachInt(value1 []byte, dataType1 jsonparser.ValueType, offset1 int, err1 error) (int64, error)

func GetJsonBool added in v0.1.13

func GetJsonBool(data []byte, keys ...string) (bool, bool, error)

GetJsonBool - everything to bool, null -> false, 0 -> false, True -> true

func GetJsonFloat added in v0.1.2

func GetJsonFloat(data []byte, keys ...string) (float64, bool, error)

func GetJsonInt added in v0.1.2

func GetJsonInt(data []byte, keys ...string) (int64, bool, error)

func GetJsonInt64Arr added in v0.1.10

func GetJsonInt64Arr(data []byte, keys ...string) ([]int64, error)

func GetJsonInt64Arr2 added in v0.1.10

func GetJsonInt64Arr2(data []byte, keys ...string) ([][]int64, error)

func GetJsonInt64Arr3 added in v0.1.10

func GetJsonInt64Arr3(data []byte, keys ...string) ([][][]int64, error)

func GetJsonIntArr added in v0.1.10

func GetJsonIntArr(data []byte, keys ...string) ([]int, error)

func GetJsonIntArr2 added in v0.1.10

func GetJsonIntArr2(data []byte, keys ...string) ([][]int, error)

func GetJsonIntArr3 added in v0.1.10

func GetJsonIntArr3(data []byte, keys ...string) ([][][]int, error)

func GetJsonObject added in v0.1.12

func GetJsonObject(data []byte,
	cb func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error,
	keys ...string) error

func GetJsonObjectArr added in v0.1.10

func GetJsonObjectArr(data []byte, cb func(value []byte, dataType jsonparser.ValueType, offset int, err error), keys ...string) error

func GetJsonString added in v0.1.2

func GetJsonString(data []byte, keys ...string) (string, bool, error)

GetJsonString - number to string

func HasJsonKey added in v0.1.10

func HasJsonKey(data []byte, keys ...string) bool

func IndexOfInt2Slice

func IndexOfInt2Slice(arr []int, x, y int, start int) int

IndexOfInt2Slice - indexof for []int2, []int2 is like [x0, y0, x1, y1, ...]

start * 2 <--> len([]int)

func IndexOfIntSlice

func IndexOfIntSlice(arr []int, v int, start int) int

IndexOfIntSlice - indexof for []int

func IndexOfStringSlice

func IndexOfStringSlice(arr []string, v string, start int) int

IndexOfStringSlice - indexof for []string

func Info

func Info(message string, fields ...slog.Attr)

Info logs a debug message with the given fields

func InitLogger2 added in v0.2.2

func InitLogger2(appName string, appVersion string, strLevel string, isConsole bool, logpath string)

func InsUniqueIntSlice

func InsUniqueIntSlice(arr []int, v int) []int

InsUniqueIntSlice - Insert unique int array

func Int2StringWithArr added in v0.1.46

func Int2StringWithArr(val int, arr string) string

(0, "abc") => "a", (1, "abc") => "b", (3, "abc") => "aa"

func Int32ArrToIntArr2 added in v0.1.2

func Int32ArrToIntArr2(arr []int32, x, y int) ([][]int, error)

Int32ArrToIntArr2 - []int32 to [][]int

func Int32ArrToIntArr3 added in v0.1.2

func Int32ArrToIntArr3(arr []int32, x, y, z int) ([][][]int, error)

Int32ArrToIntArr3 - []int32 to [][][]int

func Int3Arr2ToInt4Arr2 added in v0.1.2

func Int3Arr2ToInt4Arr2(arr [][]int, val int) [][]int

Int3Arr2ToInt4Arr2 - []int{x,y,z} -> []int{x,y,z,v}

func IntArr2ToInt32Arr

func IntArr2ToInt32Arr(arr [][]int) ([]int32, int, int)

IntArr2ToInt32Arr - [][]int to []int32

func IntArr3ToInt32Arr added in v0.1.2

func IntArr3ToInt32Arr(arr [][][]int) ([]int32, int, int, int)

IntArr3ToInt32Arr - [][][]int to []int32

func IsFloatEquals

func IsFloatEquals(a, b float64) bool

func IsSameFile

func IsSameFile(fna string, fnb string) bool

IsSameFile - filea == fileb

func IsSameIntArr2 added in v0.1.2

func IsSameIntArr2(arr0 [][]int, arr1 [][]int) bool

IsSameIntArr2 -

func IsSameIntArr2Ex added in v0.1.2

func IsSameIntArr2Ex(arr0 [][]int, arr1 [][]int32) bool

IsSameIntArr2Ex -

func IsSameIntArr2Ex2 added in v0.1.2

func IsSameIntArr2Ex2(arr0 [][]int, arr1 [][]int, x int) bool

IsSameIntArr2Ex - 只比较前x个

func LoadCSVFile added in v0.1.45

func LoadCSVFile(fn string, funcIsHeadRow FuncIsCSVHeadRow, funcProcCSVRow FuncProcCSVRow) error

func LoadExcel added in v0.1.50

func LoadExcel(fn string, sheet string, onheader FuncProcHeader, ondata FuncProcData) error

func LoadVersion added in v0.1.22

func LoadVersion(fn string) (string, error)

func MapI64I2MapI64I32 added in v0.1.17

func MapI64I2MapI64I32(mapII map[int64]int) map[int64]int32

MapI64I2MapI64I32 - map[int64]int to map[int64]int32

func MapII2MapI32I32 added in v0.1.16

func MapII2MapI32I32(mapII map[int]int) map[int32]int32

MapII2MapI32I32 - map[int]int to map[int32]int32

func Pos2Cell added in v0.1.18

func Pos2Cell(x, y int) string

Pos2Cell - (0, 0) -> A1, (1, 0) -> B1, (0, 1) -> A2

func Rune2Int

func Rune2Int(r rune) int

Rune2Int

func String2Float64 added in v0.1.2

func String2Float64(str string) (float64, error)

func String2Int64 added in v0.1.2

func String2Int64(str string) (int64, error)

func Warn

func Warn(message string, fields ...slog.Attr)

Warn logs a debug message with the given fields

Types

type FuncIsCSVHeadRow added in v0.1.45

type FuncIsCSVHeadRow func(i int, row []string) bool

type FuncProcCSVRow added in v0.1.45

type FuncProcCSVRow func(i int, row []string, mapHeader map[int]string) error

type FuncProcData added in v0.1.50

type FuncProcData func(x int, y int, header string, data string) error

type FuncProcHeader added in v0.1.50

type FuncProcHeader func(x int, str string) string

type ITime

type ITime interface {
	// Now - get now time
	Now() time.Time
}

ITime - Time

type MapWeights added in v0.1.47

type MapWeights struct {
	MapWeights  map[string]int
	TotalWeight int
	DefaultName string
}

func NewMapWeights added in v0.1.47

func NewMapWeights() *MapWeights

func (*MapWeights) AddWeight added in v0.1.47

func (mapWeights *MapWeights) AddWeight(name string, weight int, isDefault bool) error

func (*MapWeights) Rand added in v0.1.47

func (mapWeights *MapWeights) Rand() string

func (*MapWeights) SetDefaultIsMaxWeight added in v0.1.48

func (mapWeights *MapWeights) SetDefaultIsMaxWeight()

type MockITime

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

MockITime is a mock of ITime interface

func NewMockITime

func NewMockITime(ctrl *gomock.Controller) *MockITime

NewMockITime creates a new mock instance

func (*MockITime) EXPECT

func (m *MockITime) EXPECT() *MockITimeMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockITime) Now

func (m *MockITime) Now() time.Time

Now mocks base method

type MockITimeMockRecorder

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

MockITimeMockRecorder is the mock recorder for MockITime

func (*MockITimeMockRecorder) Now

func (mr *MockITimeMockRecorder) Now() *gomock.Call

Now indicates an expected call of Now

type SenderStats added in v0.1.41

type SenderStats struct {
	MapNodes     map[string]*SenderStatsNode `json:"mapMsgs,omitempty"`
	MaxNodes     int                         `json:"-"`
	ChanState    chan int                    `json:"-"`
	TickerOutput *time.Ticker                `json:"-"`
	PathOutput   string                      `json:"-"`
	// contains filtered or unexported fields
}

func NewSenderStats added in v0.1.41

func NewSenderStats(maxNodes int, chanSize int, outputTimer time.Duration, pathOutput string, prefixFN string) *SenderStats

func (*SenderStats) Output added in v0.1.41

func (stats *SenderStats) Output()

func (*SenderStats) Push added in v0.1.41

func (stats *SenderStats) Push(name string, bytes int)

func (*SenderStats) Start added in v0.1.41

func (stats *SenderStats) Start()

func (*SenderStats) Stop added in v0.1.41

func (stats *SenderStats) Stop()

type SenderStatsNode added in v0.1.41

type SenderStatsNode struct {
	Name       string `json:"name,omitempty"`
	TotalBytes int64  `json:"totalBytes,omitempty"`
	TotalTimes int    `json:"totalTimes,omitempty"`
	MaxBytes   int    `json:"maxBytes,omitempty"`
	MinBytes   int    `json:"minBytes,omitempty"`
	Nodes      []int  `json:"nodes,omitempty"`
}

type ServStats added in v0.1.22

type ServStats struct {
	MapMsgs      map[string]*ServStatsMsg `json:"mapMsgs,omitempty"`
	MaxNodes     int                      `json:"-"`
	ChanState    chan int                 `json:"-"`
	TickerOutput *time.Ticker             `json:"-"`
	PathOutput   string                   `json:"-"`
	// contains filtered or unexported fields
}

func NewServStats added in v0.1.22

func NewServStats(maxNodes int, chanSize int, outputTimer time.Duration, pathOutput string, poolSize int, prefixFN string) *ServStats

func (*ServStats) EndMsg added in v0.1.22

func (stats *ServStats) EndMsg(msgname string, node *ServStatsMsgNode)

func (*ServStats) Output added in v0.1.33

func (stats *ServStats) Output()

func (*ServStats) RegMsg added in v0.1.25

func (stats *ServStats) RegMsg(name string)

func (*ServStats) Start added in v0.1.22

func (stats *ServStats) Start()

func (*ServStats) StartMsg added in v0.1.22

func (stats *ServStats) StartMsg(msgname string) *ServStatsMsgNode

func (*ServStats) Stop added in v0.1.22

func (stats *ServStats) Stop()

type ServStatsMsg added in v0.1.22

type ServStatsMsg struct {
	Name         string    `json:"name,omitempty"`
	TotalTime    float64   `json:"totalTime,omitempty"`
	TotalTimes   int       `json:"totalTimes,omitempty"`
	MaxTime      float64   `json:"maxTime,omitempty"`
	MinTime      float64   `json:"minTime,omitempty"`
	MaxParallels int       `json:"maxParallels,omitempty"`
	Nodes        []float64 `json:"nodes,omitempty"`

	LastMsgNums int `json:"lastMsgNums"`
	// contains filtered or unexported fields
}

type ServStatsMsgNode added in v0.1.22

type ServStatsMsgNode struct {
	Start time.Time
	End   time.Time
}

type Time

type Time struct {
}

Time - default Time

func (Time) Now

func (t Time) Now() time.Time

Now - get now time

type VersionObj added in v0.1.22

type VersionObj struct {
	Major int
	Minor int
	Patch int
}

func ParseVersion added in v0.1.22

func ParseVersion(str string) (*VersionObj, error)

func (*VersionObj) IncPatch added in v0.1.22

func (vobj *VersionObj) IncPatch()

func (*VersionObj) ToString added in v0.1.22

func (vobj *VersionObj) ToString() string

Jump to

Keyboard shortcuts

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