Documentation ¶
Index ¶
- Constants
- Variables
- func CloseEnuf(a, b float64) bool
- func CloseInt(a, b int) bool
- func CoerceFloat(v interface{}) (float64, error)
- func CoerceFloatShort(v interface{}) float64
- func CoerceInt(v interface{}) (int, error)
- func CoerceInt64(v interface{}) (int64, error)
- func CoerceInt64Short(v interface{}) int64
- func CoerceIntShort(v interface{}) int
- func CoerceString(v interface{}) (string, error)
- func CoerceStringShort(v interface{}) string
- func CoerceUint(v interface{}) (uint64, error)
- func CoerceUintShort(v interface{}) uint64
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func DeleteJson(url, body string) (ret string, err error, resp *http.Response)
- func DiscardStandardLogger()
- func DoLog(depth, logLvl int, msg string)
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fetch(url string) (ret []byte, err error)
- func FetchResp(url string) (ret []byte, err error, resp *http.Response)
- func GetErrLogger() *log.Logger
- func GetLogger() *log.Logger
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func IsTerminal() bool
- func JsonString(v interface{}) string
- func Log(logLvl int, v ...interface{})
- func LogD(depth int, logLvl int, v ...interface{})
- func LogLevelSet(levelWord string)
- func LogP(logLvl int, prefix string, v ...interface{})
- func LogPf(logLvl int, prefix string, format string, v ...interface{})
- func LogTracef(logLvl int, format string, v ...interface{})
- func Logf(logLvl int, format string, v ...interface{})
- func MakeJsonList(b []byte) []byte
- func NewUid() uint64
- func PostForm(url, body string) (ret string, err error, resp *http.Response)
- func PostJson(url, body string) (ret string, err error, resp *http.Response)
- func PutJson(url, body string) (ret string, err error, resp *http.Response)
- func SetColorIfTerminal()
- func SetColorOutput()
- func SetErrLogger(l *log.Logger, logLevel string)
- func SetLogger(l *log.Logger, logLevel string)
- func SetStopper(f func())
- func SetupLogging(lvl string)
- func SetupLoggingLong(lvl string)
- func StartTest()
- func StopCheck()
- func WaitFor(check func() bool, timeoutSecs int)
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type DevNull
- type JsonHelper
- func (j JsonHelper) Bool(n string) bool
- func (j JsonHelper) BoolSafe(n string) (val bool, ok bool)
- func (j JsonHelper) Get(n string) interface{}
- func (j JsonHelper) Helper(n string) JsonHelper
- 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) List(n string) []interface{}
- func (j JsonHelper) Map(n string) map[string]interface{}
- func (j JsonHelper) MapSafe(n string) (map[string]interface{}, 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
- type JsonInterface
- func (j *JsonInterface) Encode() ([]byte, error)
- func (j *JsonInterface) Float() (float32, error)
- func (j JsonInterface) FloatSh() float32
- func (j *JsonInterface) Int() (int, error)
- func (j JsonInterface) IntSh() int
- func (j *JsonInterface) MarshalJSON() ([]byte, error)
- func (j *JsonInterface) String() (string, error)
- func (j JsonInterface) StringSh() string
- func (j *JsonInterface) UnmarshalJSON(raw []byte) error
- type JsonRawWriter
- type Uid
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 CoerceFloatShort(v interface{}) float64
func CoerceInt64 ¶
func CoerceInt64Short ¶
func CoerceInt64Short(v interface{}) int64
func CoerceIntShort ¶
func CoerceIntShort(v interface{}) int
func CoerceString ¶
Coerce types (string,int,int64, float, []byte) into String type
func CoerceStringShort ¶
func CoerceStringShort(v interface{}) string
Coerce type to string, returning zero length string if error or nil
func CoerceUint ¶
Coerce a val(interface{}) into a Uint64
func CoerceUintShort ¶
func CoerceUintShort(v interface{}) uint64
Coerce a Val(interface{}) into Uint64
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 GetErrLogger ¶
func JsonString ¶
func JsonString(v interface{}) string
func LogD ¶
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...) }
func LogPf ¶
Log to logger if setup with a prefix
LogPf(ERROR, "prefix", "formatString %s %v", anyItems, youWant)
func LogTracef ¶
Log to logger if setup, grab a stack trace and add that as well
u.LogTracef(u.ERROR, "message %s", varx)
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 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 seperate 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 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)
Types ¶
type DevNull ¶
type DevNull struct{}
http://play.golang.org/p/5LIA41Iqfp Dummy discard, satisfies io.Writer without importing io or os.
type JsonHelper ¶
type JsonHelper map[string]interface{}
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 interface{}) (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) Get ¶
func (j JsonHelper) Get(n string) interface{}
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) Helper ¶
func (j JsonHelper) Helper(n string) JsonHelper
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) Ints ¶
func (j JsonHelper) Ints(n string) []int
func (JsonHelper) Map ¶
func (j JsonHelper) Map(n string) map[string]interface{}
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
type JsonInterface ¶
type JsonInterface struct {
// contains filtered or unexported fields
}
A simple wrapper to help json data be consumed when not using Strongly typed structs.
func (*JsonInterface) Encode ¶
func (j *JsonInterface) Encode() ([]byte, error)
Encode returns its marshaled data as `[]byte`
func (*JsonInterface) Float ¶
func (j *JsonInterface) Float() (float32, error)
Coerce to Float, return err if needed
func (JsonInterface) FloatSh ¶
func (j JsonInterface) FloatSh() float32
Coerce to Float, 0 returned if 0 or missing
func (JsonInterface) IntSh ¶
func (j JsonInterface) IntSh() int
Coerce to Int, 0 returned if missing or zero
func (*JsonInterface) MarshalJSON ¶
func (j *JsonInterface) MarshalJSON() ([]byte, error)
Implements the json.Marshaler interface.
func (JsonInterface) StringSh ¶
func (j JsonInterface) StringSh() string
Coerce to a string, may be zero length if missing, or zero length
func (*JsonInterface) UnmarshalJSON ¶
func (j *JsonInterface) UnmarshalJSON(raw []byte) error
Implements the json.Unmarshal interface.
type JsonRawWriter ¶
func (*JsonRawWriter) MarshalJSON ¶
func (m *JsonRawWriter) MarshalJSON() ([]byte, error)
func (*JsonRawWriter) Raw ¶
func (m *JsonRawWriter) Raw() json.RawMessage