gox

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 20 Imported by: 10

README

gox

Golang Extra Functions/Utilities

Documentation

Index

Constants

View Source
const (
	Trace int = iota
	Debug
	Info
	Remark
	Warn
	Error
)

specify logger level

Variables

This section is empty.

Functions

func Cors

Cors sets http headers

func CountLines

func CountLines(reader *bufio.Reader) (int, error)

CountLines count number of '\n'

func GetDurationFromSeconds

func GetDurationFromSeconds(seconds float64) string

GetDurationFromSeconds converts seconds to time string, e.g. 1.5m

func GetRandomDigitString

func GetRandomDigitString(n int) string

GetRandomDigitString returns a random digit string

func GetRandomHexString

func GetRandomHexString(n int) string

GetRandomHexString returns a random hex string

func GetRandomUUIDString

func GetRandomUUIDString() string

GetRandomUUIDString returns a random UUID string

func GetStorageSize

func GetStorageSize(num interface{}) string

GetStorageSize returns storage size in [TGMK] B

func HTTPDigest

func HTTPDigest(method string, uri string, username string, password string, headers map[string]string, body ...[]byte) (*http.Response, error)

HTTPDigest --digest

func MilliToTimeString

func MilliToTimeString(milli float64) string

MilliToTimeString converts milliseconds to time string, e.g. 1.5m

func NewFileReader

func NewFileReader(filename string) (*bufio.Reader, error)

NewFileReader returns a reader from either a gzip or plain file

func NewReader

func NewReader(file *os.File) (*bufio.Reader, error)

NewReader returns a reader from either a gzip or plain file

func OutputGzipped

func OutputGzipped(b []byte, filename string) error

OutputGzipped writes doc to a gzipped file

func ReadAll

func ReadAll(file *os.File) ([]byte, error)

ReadAll reads from a file and return bytes

func StartWebServer

func StartWebServer(port int) error

StartWebServer starts a web server

func Stringify

func Stringify(doc interface{}, opts ...string) string

Stringify returns a string of a map

func ToFloat64

func ToFloat64(num interface{}) (float64, error)

ToFloat64 converts any data type to float64

func ToInt64

func ToInt64(num interface{}) (int64, error)

ToInt64 converts any data type to int64

func ZipFiles

func ZipFiles(zipFilename string, filenames []string) error

ZipFiles zips files into a zip archive

Types

type Logger

type Logger struct {
	AppName string   `json:"version" bson:"version"`
	Logs    []string `json:"logs" bson:"logs"`
	// contains filtered or unexported fields
}

Logger stores logger info

func GetLogger

func GetLogger(appName string) *Logger

GetLogger returns Logger instance

func (*Logger) Debug

func (p *Logger) Debug(v ...interface{})

Debug adds and prints a message

func (*Logger) Debugf

func (p *Logger) Debugf(format string, v ...interface{})

Debugf adds and prints a message

func (*Logger) Error

func (p *Logger) Error(v ...interface{})

Error adds and prints an error message

func (*Logger) Errorf

func (p *Logger) Errorf(format string, v ...interface{})

Errorf adds and prints a message

func (*Logger) Info

func (p *Logger) Info(v ...interface{})

Info adds and prints a message

func (*Logger) Infof

func (p *Logger) Infof(format string, v ...interface{})

Infof adds and prints a message

func (*Logger) Print

func (p *Logger) Print() string

Print prints all Logs

func (*Logger) Remark added in v0.2.2

func (p *Logger) Remark(v ...interface{})

Remark adds and prints a message

func (*Logger) Remarkf added in v0.2.2

func (p *Logger) Remarkf(format string, v ...interface{})

Remarkf adds and prints a message

func (*Logger) SetLoggerLevel

func (p *Logger) SetLoggerLevel(level int)

SetLoggerLevel sets logger level

func (*Logger) Trace

func (p *Logger) Trace(v ...interface{})

Trace adds and prints a message

func (*Logger) Tracef

func (p *Logger) Tracef(format string, v ...interface{})

Tracef adds and prints a message

func (*Logger) Warn

func (p *Logger) Warn(v ...interface{})

Warn adds and prints a warning message

func (*Logger) Warnf

func (p *Logger) Warnf(format string, v ...interface{})

Warnf adds and prints a message

type MapWalker

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

MapWalker is an empty JSON document

func NewMapWalker

func NewMapWalker(cb callback) *MapWalker

NewMapWalker returns a MapWalker

func (*MapWalker) GetMaxArrayLength

func (walker *MapWalker) GetMaxArrayLength() int

GetMaxArrayLength return the max array length

func (*MapWalker) GetNestedLevel

func (walker *MapWalker) GetNestedLevel() int

GetNestedLevel return the level of nested document

func (*MapWalker) SetCallBack

func (walker *MapWalker) SetCallBack(cb callback)

SetCallBack defines callback function

func (*MapWalker) Walk

func (walker *MapWalker) Walk(v interface{}) interface{}

Walk walks a map

type MongoLog

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

MongoLog stores a line of mongo log

func NewMongoLog

func NewMongoLog(log string) *MongoLog

NewMongoLog returns a mongo log struct

func (*MongoLog) Get

func (ml *MongoLog) Get(key string) string

Get returns a JSON string of a tag

type OrderedMap

type OrderedMap struct {
	SortedKeys []string
	Map        map[string]interface{}
}

OrderedMap preserves keys order

func NewOrderedMap

func NewOrderedMap(str string) *OrderedMap

NewOrderedMap returns an ordered map

func (OrderedMap) MarshalJSON

func (om OrderedMap) MarshalJSON() ([]byte, error)

MarshalJSON is used by json.Marshal

func (*OrderedMap) UnmarshalJSON

func (om *OrderedMap) UnmarshalJSON(b []byte) error

UnmarshalJSON is used by json.Unmarshal

type WaitGroup

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

WaitGroup -

func NewWaitGroup

func NewWaitGroup(size int) *WaitGroup

NewWaitGroup -

func (*WaitGroup) Add

func (wg *WaitGroup) Add(num int)

Add -

func (*WaitGroup) Done

func (wg *WaitGroup) Done()

Done -

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait()

Wait -

Jump to

Keyboard shortcuts

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