Documentation
¶
Index ¶
- Constants
- Variables
- func CloseEnuf(a, b float64) bool
- func CloseInt(a, b int) bool
- func CoerceFloat(v any) (float64, error)
- func CoerceFloatShort(v any) float64
- func CoerceFloats(v any) []float64
- func CoerceInt(v any) (int, error)
- func CoerceInt64(v any) (int64, error)
- func CoerceInt64Short(v any) int64
- func CoerceIntShort(v any) int
- func CoerceInts(v any) []int
- func CoerceString(v any) (string, error)
- func CoerceStringShort(v any) string
- func CoerceStrings(v any) []string
- func CoerceUint(v any) (uint64, error)
- func CoerceUintShort(v any) uint64
- func Debug(v ...any)
- func DebugCtx(ctx context.Context, format string, v ...any)
- func DebugT(lineCt int)deprecated
- func Debugf(format string, v ...any)
- func DeleteJson(url, body string) (ret string, err error, resp *http.Response)
- func DiscardStandardLogger()
- func DoLog(depth, logLvl int, msg string)
- func DoLogFields(depth, logLvl int, msg string, fields map[string]any)
- func Error(v ...any)
- func ErrorCtx(ctx context.Context, format string, v ...any)
- func Errorf(format string, v ...any)
- func EscapeNewlines(str string) string
- func Fetch(url string) (ret []byte, err error)
- func FetchResp(url string) (ret []byte, err error, resp *http.Response)
- func FromContext(ctx context.Context) string
- func GetErrLogger() *log.Logger
- func GetLogger() *log.Logger
- func Info(v ...any)
- func InfoCtx(ctx context.Context, format string, v ...any)
- func InfoT(lineCt int)
- func Infof(format string, v ...any)
- func IsJson(by []byte) bool
- func IsJsonArray(by []byte) bool
- func IsJsonObject(by []byte) bool
- func JsonString(v any) string
- func Log(logLvl int, v ...any)deprecated
- func LogCtx(ctx context.Context, depth, logLvl int, format string, v ...any)
- func LogD(depth int, logLvl int, v ...any)deprecated
- func LogErrorf(format string, v ...any) error
- func LogFieldsf(logLvl int, fields map[string]any, format string, v ...any)deprecated
- func LogLevelSet(levelWord string)
- func LogP(logLvl int, prefix string, v ...any)deprecated
- func LogPf(logLvl int, prefix string, format string, v ...any)deprecated
- func LogThrottle(logLvl, limit int, format string, v ...any)
- func LogThrottleCtx(ctx context.Context, logLvl, limit int, format string, v ...any)
- func LogThrottleD(depth, logLvl, limit int, format string, v ...any)
- func LogThrottleKey(logLvl, limit int, key, format string, v ...any)
- func LogThrottleKeyCtx(ctx context.Context, logLvl, limit int, key, format string, v ...any)
- func LogTraceDf(logLvl, lineCt int, format string, v ...any)deprecated
- func LogTracef(logLvl int, format string, v ...any)deprecated
- func Logf(logLvl int, format string, v ...any)deprecated
- func MakeJsonList(b []byte) []byte
- func NewContext(ctx context.Context, msg string) context.Context
- func NewContextWrap(ctx context.Context, msg string) context.Context
- func PostForm(url, body string) (ret string, err error, resp *http.Response)
- func PostJson(postUrl string, data any) (ret string, err error, resp *http.Response)
- func PrettyStack(lineCt int) string
- func PutJson(url, body string) (ret string, err error, resp *http.Response)
- func SetColorOutput()
- func SetCustomLogger(cl LoggerCustom)
- func SetErrLogger(l *log.Logger, logLevel string)
- func SetEscapeNewlines(en bool)
- func SetLogger(l *log.Logger, logLevel string)
- func SetStopper(f func())
- func SetupLogging(lvl string)
- func SetupLoggingFile(f *os.File, lvl string)
- func SetupLoggingLong(lvl string)
- func StartTest()
- func StopCheck()
- func WaitFor(check func() bool, timeoutSecs int)
- func Warn(v ...any)
- func WarnCtx(ctx context.Context, format string, v ...any)
- func WarnT(lineCt int)
- func Warnf(format string, v ...any)
- type DevNull
- type JsonHelper
- func (j JsonHelper) Bool(n string) bool
- func (j JsonHelper) BoolSafe(n string) (val bool, ok bool)
- func (j *JsonHelper) DecodeSpanner(val any) (err error)
- func (j JsonHelper) EncodeSpanner() (any, error)
- func (j JsonHelper) Float64(n string) float64
- func (j JsonHelper) Float64Safe(n string) (float64, bool)
- func (j JsonHelper) Get(n string) any
- func (j *JsonHelper) GobDecode(data []byte) error
- func (j *JsonHelper) GobEncode() ([]byte, error)
- func (j JsonHelper) HasKey(name string) bool
- func (j JsonHelper) HasKeyV2(name string) bool
- func (j JsonHelper) Helper(n string) JsonHelper
- func (j JsonHelper) HelperSafe(n string) (JsonHelper, bool)
- func (j JsonHelper) Helpers(n string) []JsonHelper
- func (j JsonHelper) Int(n string) int
- func (j JsonHelper) Int64(n string) int64
- func (j JsonHelper) Int64Safe(n string) (int64, bool)
- func (j JsonHelper) IntSafe(n string) (int, bool)
- func (j JsonHelper) Ints(n string) []int
- func (j JsonHelper) Keys() []string
- func (j JsonHelper) List(n string) []any
- func (j JsonHelper) Map(n string) map[string]any
- func (j JsonHelper) MapSafe(n string) (map[string]any, bool)
- func (j JsonHelper) PrettyJson() []byte
- func (j JsonHelper) String(n string) string
- func (j JsonHelper) StringSafe(n string) (string, bool)
- func (j JsonHelper) Strings(n string) []string
- func (j JsonHelper) Uint64(n string) uint64
- func (j JsonHelper) Uint64Safe(n string) (uint64, bool)
- type LoggerCustom
- type Throttler
Constants ¶
const ( MaxInt = 1<<(BitsPerWord-1) - 1 // either 1<<31 - 1 or 1<<63 - 1 MinInt = -MaxInt - 1 // either -1 << 31 or -1 << 63 MaxUint = 1<<BitsPerWord - 1 // either 1<<32 - 1 or 1<<64 - 1 )
Implementation-specific integer limit values.
const ( NOLOGGING = -1 FATAL = 0 ERROR = 1 WARN = 2 INFO = 3 DEBUG = 4 )
const BitsPerWord = bitsPerWord // either 32 or 64
Implementation-specific size of int and uint in bits.
Variables ¶
var ( LogLevel int = ERROR EMPTY struct{} ErrLogLevel int = ERROR LogColor = map[int]string{FATAL: "\033[0m\033[37m", ERROR: "\033[0m\033[31m", WARN: "\033[0m\033[33m", INFO: "\033[0m\033[35m", DEBUG: "\033[0m\033[34m"} LogPrefix = map[int]string{ FATAL: "[FATAL] ", ERROR: "[ERROR] ", WARN: "[WARN] ", INFO: "[INFO] ", DEBUG: "[DEBUG] ", } LogLevelWords map[string]int = map[string]int{"fatal": 0, "error": 1, "warn": 2, "info": 3, "debug": 4, "none": -1} )
Functions ¶
func CoerceFloat ¶
func CoerceFloatShort ¶
func CoerceFloats ¶
func CoerceInt64 ¶
func CoerceInt64Short ¶
func CoerceIntShort ¶
func CoerceInts ¶
func CoerceString ¶
Coerce types (string,int,int64, float, []byte) into String type
func CoerceStringShort ¶
Coerce type to string, returning zero length string if error or nil
func CoerceStrings ¶
CoerceStrings Coerce type to strings, will split on comma by default.
func DeleteJson ¶
issues http delete an application/json to url with body
func DiscardStandardLogger ¶
func DiscardStandardLogger()
Setup default log output to go to a dev/null
log.SetOutput(new(DevNull))
func DoLogFields ¶
DoLogFields allows the inclusion of additional context for logrus logs file and line number are included in the fields by default Deprecated: Use zap logging
func EscapeNewlines ¶
Replace standard newline characters with escaped newlines so long msgs will remain one line.
func FromContext ¶
FromContext extracts the Log Context prefix from context
func GetErrLogger ¶
func IsJson ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonArray ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonObject ¶
func JsonString ¶
func LogCtx ¶
LogCtx Low level log with depth , level, message and logger Deprecated: Use zap logging
func LogD
deprecated
When you want to use the log short filename flag, and want to use the lower level logging functions (say from an *Assert* type function) you need to modify the stack depth:
func init() {}
SetLogger(log.New(os.Stderr, "", log.Ltime|log.Lshortfile|log.Lmicroseconds), lvl)
}
func assert(t *testing.T, myData) {
// we want log line to show line that called this assert, not this line
LogD(5, DEBUG, v...)
}
Deprecated: Use zap logging
func LogThrottle ¶
LogThrottleD logging based on @format as a key, such that key would never occur more than @limit times per hour
LogThrottle(u.ERROR, 1, "message %s", varx)
func LogThrottleCtx ¶
LogThrottleCtx log formatted context writer, limits to @limit/hour.
func LogThrottleD ¶
LogThrottleD Throttle logging based on @format as a key, such that key would never occur more than @limit times per hour
LogThrottleD(5, u.ERROR, 1, "message %s", varx)
func LogThrottleKey ¶
Throttle logging based on key, such that key would never occur more than @limit times per hour
LogThrottleKey(u.ERROR, 1,"error_that_happens_a_lot" "message %s", varx)
func LogThrottleKeyCtx ¶
LogThrottleKeyCtx log formatted context writer
func LogTraceDf
deprecated
func NewContext ¶
NewContext returns a new Context carrying contextual log message that gets prefixed to log statements. Deprecated: Use zap logging
func NewContextWrap ¶
NewContextWrap returns a new Context carrying contextual log message that gets prefixed to log statements. Deprecated: Use zap logging
func PrettyStack ¶
PrettyStack is a helper to pull stack-trace, prettify it. Deprecated: Use zap logging
func SetCustomLogger ¶
func SetCustomLogger(cl LoggerCustom)
SetCustomLogger sets the logger to a custom logger
func SetErrLogger ¶
you can set a logger, and log level. this is for errors, and assumes you are logging to Stderr (seperate from stdout above), allowing you to seperate debug&info logging from errors
gou.SetLogger(log.New(os.Stderr, "", log.LstdFlags), "debug") loglevls: debug, info, warn, error, fatal
func SetEscapeNewlines ¶
func SetEscapeNewlines(en bool)
Set whether to escape newline characters in log messages
func SetLogger ¶
you can set a logger, and log level,most common usage is:
gou.SetLogger(log.New(os.Stdout, "", log.LstdFlags), "debug") loglevls: debug, info, warn, error, fatal
Note, that you can also set a separate Error Log Level
func SetStopper ¶
func SetStopper(f func())
Use this in combo with StopCheck() for test functions that must start processes such as
func SetupLogging ¶
func SetupLogging(lvl string)
Setup default logging to Stderr, equivalent to:
gou.SetLogger(log.New(os.Stderr, "", log.Ltime|log.Lshortfile), "debug")
func SetupLoggingFile ¶
SetupLoggingFile writes logs to the file object parameter.
func SetupLoggingLong ¶
func SetupLoggingLong(lvl string)
Setup default logging to Stderr, equivalent to:
gou.SetLogger(log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds), level)
func WaitFor ¶
Wait for condition (defined by func) to be true this is mostly for testing, but a utility to create a ticker checking back every 100 ms to see if something (the supplied check func) is done
WaitFor(func() bool {
return ctr.Ct == 0
},10)
timeout (in seconds) is the last arg
Types ¶
type DevNull ¶
type DevNull struct{}
http://play.golang.org/p/5LIA41Iqfp Dummy discard, satisfies io.Writer without importing io or os.
type JsonHelper ¶
A wrapper around a map[string]interface{} to facilitate coercion of json data to what you want
allows usage such as this
jh := NewJsonHelper([]byte(`{
"name":"string",
"ints":[1,5,9,11],
"int":1,
"int64":1234567890,
"MaxSize" : 1048576,
"strings":["string1"],
"nested":{
"nest":"string2",
"strings":["string1"],
"int":2,
"list":["value"],
"nest2":{
"test":"good"
}
},
"nested2":[
{"sub":5}
]
}`)
i := jh.Int("nested.int") // 2
i2 := jh.Int("ints[1]") // 5 array position 1 from [1,5,9,11]
s := jh.String("nested.nest") // "string2"
func JsonHelperHttp ¶
func JsonHelperHttp(method, urlStr string, data any) (JsonHelper, error)
Simple Fetch Wrapper, given a url it returns Helper, error Sends as type application/json, interprets whatever datatype is sent in appropriately
func NewJsonHelper ¶
func NewJsonHelper(b []byte) JsonHelper
func NewJsonHelperFromResp ¶
func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error)
Make a JsonHelper from http response. This will automatically close the response body
func NewJsonHelperReader ¶
func NewJsonHelperReader(r io.Reader) (jh JsonHelper, err error)
func NewJsonHelpers ¶
func NewJsonHelpers(b []byte) []JsonHelper
func (JsonHelper) Bool ¶
func (j JsonHelper) Bool(n string) bool
func (*JsonHelper) DecodeSpanner ¶ added in v1.0.3
func (j *JsonHelper) DecodeSpanner(val any) (err error)
func (JsonHelper) EncodeSpanner ¶ added in v1.0.3
func (j JsonHelper) EncodeSpanner() (any, error)
func (JsonHelper) Float64 ¶
func (j JsonHelper) Float64(n string) float64
func (JsonHelper) Float64Safe ¶
func (j JsonHelper) Float64Safe(n string) (float64, bool)
func (JsonHelper) Get ¶
func (j JsonHelper) Get(n string) any
Get the key (or keypath) value as interface, mostly used internally through String, etc methods
jh.Get("name.subname")
jh.Get("name/subname")
jh.Get("name.arrayname[1]")
jh.Get("name.arrayname[]")
func (*JsonHelper) GobDecode ¶
func (j *JsonHelper) GobDecode(data []byte) error
GobDecode overwrites the receiver, which must be a pointer, with the value represented by the byte slice, which was written by GobEncode, usually for the same concrete type. GobDecode([]byte) error
func (*JsonHelper) GobEncode ¶
func (j *JsonHelper) GobEncode() ([]byte, error)
func (JsonHelper) HasKey ¶
func (j JsonHelper) HasKey(name string) bool
func (JsonHelper) HasKeyV2 ¶ added in v1.1.0
func (j JsonHelper) HasKeyV2(name string) bool
HasKeyV2 doesn't assume path is a keypath, but rather a single top-level key we're looking for
func (JsonHelper) Helper ¶
func (j JsonHelper) Helper(n string) JsonHelper
func (JsonHelper) HelperSafe ¶ added in v1.0.3
func (j JsonHelper) HelperSafe(n string) (JsonHelper, bool)
Get a Helper from a string path
func (JsonHelper) Helpers ¶
func (j JsonHelper) Helpers(n string) []JsonHelper
Get list of Helpers at given name. Trys to coerce into proper Helper type
func (JsonHelper) Int ¶
func (j JsonHelper) Int(n string) int
func (JsonHelper) Int64 ¶
func (j JsonHelper) Int64(n string) int64
func (JsonHelper) Ints ¶
func (j JsonHelper) Ints(n string) []int
func (JsonHelper) Keys ¶
func (j JsonHelper) Keys() []string
func (JsonHelper) PrettyJson ¶
func (j JsonHelper) PrettyJson() []byte
func (JsonHelper) String ¶
func (j JsonHelper) String(n string) string
func (JsonHelper) StringSafe ¶
func (j JsonHelper) StringSafe(n string) (string, bool)
func (JsonHelper) Strings ¶
func (j JsonHelper) Strings(n string) []string
func (JsonHelper) Uint64 ¶
func (j JsonHelper) Uint64(n string) uint64
func (JsonHelper) Uint64Safe ¶
func (j JsonHelper) Uint64Safe(n string) (uint64, bool)
type LoggerCustom ¶
LoggerCustom defines custom interface for logger implementation
func GetCustomLogger ¶
func GetCustomLogger() LoggerCustom
GetCustomLogger returns the custom logger if initialized
type Throttler ¶
type Throttler struct {
// contains filtered or unexported fields
}
func NewThrottler ¶
new Throttler that will tell you to limit or not based on given @max events @per duration
func (*Throttler) Throttle ¶
Should we limit this because we are above rate? Returns a bool of whether to throttle the message, and a count of previous log messages throttled since last log message.
func (*Throttler) ThrottleAdd ¶
Should we limit this because we are above rate? Returns a bool of whether to throttle the message, and a count of previous log messages throttled since last log message.