goutil

package module
v0.0.0-...-42b2fd0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

README

goutil

Build Status Build status

document site

http://goutil.readthedocs.io/

Description

goutil is just a collection of go common used method

serval import struct or method

Statistics

Statistics is used to stat realtime data in a web server or a backgroud service
It contain a main type and a sub type, and the third is the key string you want to calculate

eg: Type:API SubType: User Key:get

statis := NewStatistics(10000, 10, "2006-01-02 15:04:05", MockGetTime)
item := Item{Type:"API", SubType:"User", Key:"get"}
statis.AddItem(item)

//Get a data value
data := statis.GetInfoByTypeAndSubType("API", "User")
// data format
// map["time"] = "2017-01-01 12:12:00"
// map["get] = 123
GetDayRange

GetDayRange is used to get a range of start and end time, see the comment for usage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(str string) ([]byte, error)

func Base64Encode

func Base64Encode(str string) string

func GetCurrentTimeStr

func GetCurrentTimeStr() string

GetCurrentTimeStr is used to get current time str with format "2006-01-02 15:04:05"

func GetDayRange

func GetDayRange(start string, end string, format string) ([]string, error)

GetDayRange is used to get a range of start and end time start string eg:2017-01-02 end string eg:2017-01-22 format string eg: 2006-01-02 result: ["2017-01-02","2017-01-03",...,"2017-01-21"]

func GetRandInt

func GetRandInt() int

func GetRandInt32

func GetRandInt32() int32

func GetRanddomString

func GetRanddomString(num int) string

func GetResidueRandom

func GetResidueRandom(num int) int

func IsAbsolutePath

func IsAbsolutePath(path string) bool

IsAbsolutePath is used to check path is absolute path

func IsDirExists

func IsDirExists(path string) bool

IsDirExists is used to check dir is exist or not

func IsFileExist

func IsFileExist(path string) bool

IsFileExist is used to check file exist or not

func ListDirFiles

func ListDirFiles(dirPath string, suffix string) (interface{}, error)

ListDirFiles is used to get all files in one path map[string]interface{}

func Md5

func Md5(str string) string

func SubStr

func SubStr(str string, start int, end int) string

func SubStrByOffset

func SubStrByOffset(str string, start int, offset int) string

Types

type Info

type Info struct {
	Time time.Time
	Data map[string]uint64
}

type Item

type Item struct {
	Type    string
	SubType string
	Key     string
}

type Statistics

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

func NewStatistics

func NewStatistics(itemLength int, dataLength int, timeFormat string, timeFunc func() time.Time) *Statistics

func (*Statistics) AddItem

func (s *Statistics) AddItem(item Item)

func (*Statistics) GetInfoByType

func (s *Statistics) GetInfoByType(typeStr string) interface{}

func (*Statistics) GetInfoByTypeAndSubType

func (s *Statistics) GetInfoByTypeAndSubType(typeStr string, subType string) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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