rover

package
v0.0.0-...-4dae00c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: GPL-3.0 Imports: 24 Imported by: 2

Documentation

Overview

gorover implement methods like file path, time range, save data to json, cmd input data, randon string, etc.

Index

Constants

View Source
const DefaultTimeFormat = "2006-01-02T15:04:05-0700"

Variables

View Source
var (
	KVShareClosed   = errors.New("channel is closed")
	KVShareNotFound = errors.New("key not found")
)
View Source
var CMSE_RELEASE_MODE = true
View Source
var DeafultTimeFormat = "[2006-01-02T15:04:05-0700]"
View Source
var Rand *rand.Rand

Functions

func Base62Decode

func Base62Decode(str string) (num int64, err error)

func Base62Encode

func Base62Encode(num int64) (result string)

func BatchJSON

func BatchJSON(n int, do func([]byte) error) func(interface{}, bool) error

func BindError

func BindError(e1, e2 error) (err error)

func Bts2File

func Bts2File(bts []byte, out string) (err error)

// Save bytes and string to file save []byte to file (and create parent directories)

func Columns

func Columns(array [][]string, prefixSpaces, padding int)

// Path print slice of string slice in align text

func DecomposePath

func DecomposePath(p string) (dir, base, ext string, err error)

return file parent directory, basename and extend name

func Divmod

func Divmod(a, b int) (d, m int)

func FixTimeUnit

func FixTimeUnit(in string) (out string, err error)

func GrowthRatioInPerc

func GrowthRatioInPerc(a, b int) (ratio float64)

calculate growth ratio from a to b in percentage

func IndexInt

func IndexInt(slice []int, value int) (p int)

func IndexInt64

func IndexInt64(slice []int64, value int64) (p int)

func IndexString

func IndexString(slice []string, value string) (p int)

// Index

func InvalidTimeUint

func InvalidTimeUint() (err error)

func IsMD5

func IsMD5(str string) (err error)

func IsMD5Lower

func IsMD5Lower(str string) (err error)

func IsMD5Upper

func IsMD5Upper(str string) (err error)

func JsonStr

func JsonStr(data interface{}, readable bool) (str string, err error)

func JsonTo

func JsonTo(data interface{}, out io.Writer, readable bool) (err error)

marshal data to json([]byte), and write to an io.Writer,

func JsonToFile

func JsonToFile(data interface{}, out string, readable bool) (err error)

masharshal data to json([]byte) and save to file, parents directories of file will be created

func JsonToStdout

func JsonToStdout(data interface{}) (err error)

masharshal data to json([]byte) to os.Stdout

func LogErr

func LogErr(tag string, err error)

log error, print error even it's nil

func Param2URL

func Param2URL(param map[string]string, secrete, signKey string,
	signFunc func(map[string]string, string) string) (urlQuery string)

func ParseNTU

func ParseNTU(str string) (n int64, unit string, err error)

func Percentage

func Percentage(a, b int64) (per float64)

func PrintData

func PrintData(data interface{})

print data to stdout in json format

func PrintErr

func PrintErr(tag string, err error, items ...interface{})

// Log Error print error to console when err != nil for debug

func QuerySignInMD5

func QuerySignInMD5(param map[string]string, secrete, signKey string) (
	urlQuery string)

func RandAlphanumeric

func RandAlphanumeric(length int) string

generate alphanumeric string with fixed length

func RandomStr

func RandomStr(l int, t int) (s string, err error)

generate random string with fixed length type is a 5 bit length binary number which represent numbers, upper letters, lower letters, special characters and space from lower to higher

func RealPath

func RealPath(p string) (realpath string, err error)

return file realpath

func SaveData

func SaveData(d interface{}, p string)

save data in json

func SignParamInMD5

func SignParamInMD5(param map[string]string, secrete string) (signValue string)

sort parameter by keys in ASCII, concat all key+value, add secrete in header and tail, then calculate MD5 value of string

func Str2File

func Str2File(str, out string) (err error)

func TimeCeil

func TimeCeil(from time.Time, tu string) (nt time.Time, err error)

func TimeConvert

func TimeConvert(ty, str string) (result string, err error)

Convert between int64 and time, type example s2t, t2u,

s for Second, m for Millisecond, u for Microsecond, n for Nanosecond
t for time in format 2006-01-02T15:04:05-0700

func TimeFloor

func TimeFloor(from time.Time, tu string) (nt time.Time, err error)

func TimeScale

func TimeScale(from time.Time, str string, cof func(time.Time, string) (time.Time, error)) (
	nt time.Time, err error)

func TimeScaleRange

func TimeScaleRange(from time.Time, str string, cof func(time.Time, string) (time.Time, error)) (
	t0, t1 time.Time, err error)

func TimeWalk

func TimeWalk(from time.Time, n int64, tu string) (nt time.Time, err error)

func TimeWalkRange

func TimeWalkRange(from time.Time, n int64, tu string) (t0, t1 time.Time, err error)

func UpdateValue

func UpdateValue(x *string, mp map[string]string)

func VerifyQuerySignInMD5

func VerifyQuerySignInMD5(urlQuery string, signKey, secrete string) (
	param map[string]string, err error)

Types

type Argi

type Argi struct {
	Scanner *bufio.Scanner
	// contains filtered or unexported fields
}

argument input structure

func NewArgi

func NewArgi(name string) (input *Argi, err error)

provide input command string and return *Argi and error

func (*Argi) Close

func (input *Argi) Close()

close reader and file

func (*Argi) GetName

func (input *Argi) GetName() string

get input raw name

func (*Argi) GetType

func (input *Argi) GetType() (s string)

get input type: stdin, gzip or text

type Argx

type Argx struct {
	Start
	End
	*Logger
}

func NewArgx

func NewArgx() (argx *Argx, err error)

save command arguments to data struct Argx

func (*Argx) Done

func (argx *Argx) Done(code int, msg string)

save end information to argx.End

type CMSE

type CMSE struct {
	C     int         `json:"code"`    // response code, default 200, https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
	M     string      `json:"message"` // repsonse message to end user
	S     int         `json:"subcode"` // specify response subcode, generally, S != 0 when E isn't nil
	E     error       `json:"-"`
	D     interface{} `json:"data,omitempty"`
	Error string      `json:"error,omitempty"` //!! response with error when CMSE_RELEASE_MODE = false
}

func NewCMSE

func NewCMSE() (cmse *CMSE)

func (*CMSE) JSON

func (cmse *CMSE) JSON(w http.ResponseWriter) (err error)

func (*CMSE) SetD

func (cmse *CMSE) SetD(key string, d interface{}) (err error)

func (*CMSE) String

func (cmse *CMSE) String() (str string, err error)

type ClassCode

type ClassCode struct {
	Code uint64
	// contains filtered or unexported fields
}

func NewClassCode

func NewClassCode(elems ...ClassElem) (ec *ClassCode, err error)

func (*ClassCode) Bools

func (ec *ClassCode) Bools() (bools []bool)

func (*ClassCode) ClearAt

func (ec *ClassCode) ClearAt(n int) (err error)

func (*ClassCode) Elems

func (ec *ClassCode) Elems() (names []string)

func (*ClassCode) Num

func (ec *ClassCode) Num() int

func (*ClassCode) ToggleAt

func (ec *ClassCode) ToggleAt(n int) (err error)

func (*ClassCode) Value

func (ec *ClassCode) Value(key string) (bool, error)

type ClassElem

type ClassElem struct {
	Name  string
	Value bool
}

type Counter

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

parallel counter with buffered and RWMutex

func NewCounter

func NewCounter(n int) (counter *Counter, err error)

func (*Counter) Add

func (counter *Counter) Add(n int) (err error)

add a number

func (*Counter) Close

func (counter *Counter) Close()

close channel and method Add can't useable

func (*Counter) GetN

func (counter *Counter) GetN() (l, c int)

get channel length and capcity

func (*Counter) GetS

func (counter *Counter) GetS() bool

get channel status, close was close if return a false

func (*Counter) Sum

func (counter *Counter) Sum() int

calculate sum of counter

type Edge

type Edge struct {
	ID, N1, N2 int64

	Weight  float64
	Created time.Time
	// contains filtered or unexported fields
}

type End

type End struct {
	Code    int
	Message string
	EndAt   time.Time
	Elapsed string
}

type KVShare

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

func NewKVShare

func NewKVShare(ndata map[string]interface{}, n int) (kvs *KVShare, err error)

func (*KVShare) Close

func (kvs *KVShare) Close()

func (*KVShare) Get

func (kvs *KVShare) Get(key string) (value interface{}, err error)

func (*KVShare) Update

func (kvs *KVShare) Update(ndata map[string]interface{})

type Logger

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

func NewLogger

func NewLogger() (logger *Logger)

func (*Logger) Close

func (logger *Logger) Close() (err error)

func (*Logger) GetIndex

func (logger *Logger) GetIndex() (idx int64)

func (*Logger) Log

func (logger *Logger) Log(tag string, rs ...interface{}) (n int, err error)

write a message to logger

func (*Logger) LogBlock

func (logger *Logger) LogBlock(tag string, msg string) (n int, err error)

write a message to logger

func (*Logger) SetFile

func (logger *Logger) SetFile(fp string) (err error)

func (*Logger) SetSep

func (logger *Logger) SetSep(sep string) (err error)

func (*Logger) SetWriter

func (logger *Logger) SetWriter(w io.Writer, sep string) (err error)

set logger, writer and seperator

type Node

type Node struct {
	ID      int64
	Name    string
	Attr    map[string][]string
	Edge    []int64
	Created int64 // Seconds
}

func NewNode

func NewNode(id int64, name string) (node *Node)

type Start

type Start struct {
	Main     string
	WorkPath string
	User     string
	PID      int
	Created  time.Time
	Args     []string
}

type TimeSplitter

type TimeSplitter struct {
	Start, End time.Time
	Duration   time.Duration
	// contains filtered or unexported fields
}

//

func NewTimeSplitter

func NewTimeSplitter(start, end time.Time, d time.Duration) (
	tsp *TimeSplitter, err error)

func (*TimeSplitter) GetNK

func (tsp *TimeSplitter) GetNK() (int64, int64)

func (*TimeSplitter) Next

func (tsp *TimeSplitter) Next() (qStart, qEnd time.Time, err error)

type UpdateTrigger

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

func NewUpdateTrigger

func NewUpdateTrigger(fn func() error, d time.Duration, mustSync, atOnce bool) (
	ut *UpdateTrigger, err error)

func (*UpdateTrigger) Expired

func (ut *UpdateTrigger) Expired() bool

func (*UpdateTrigger) LastOne

func (ut *UpdateTrigger) LastOne() (time.Time, error)

func (*UpdateTrigger) ResetInterval

func (ut *UpdateTrigger) ResetInterval(d time.Duration) error

func (*UpdateTrigger) Update

func (ut *UpdateTrigger) Update() (err error)

Jump to

Keyboard shortcuts

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