Documentation
¶
Index ¶
- Constants
- Variables
- func AlignToRight(s string, size int) string
- func AlignedString(str string, lenres int, filledChar string, alignFlag AlginedFlag) (res string)
- func Amax(x ...float64) (idx int, xmax float64, err error)
- func AppendToFile(fn string, buffer ...*bytes.Buffer)
- func ArgsTable(title string, data ...interface{}) string
- func ArgsTableN(title string, nledsp int, isleft bool, heads []string, data ...interface{}) string
- func Atob(val string) (bres bool)
- func Atof(val string) (res float64)
- func Atoi(val string) (res int)
- func BtoStr(bs []byte) string
- func Btoa(flag bool) string
- func Btoi(flag bool) int
- func BytesSizeToString(byteCount int) string
- func CallerInfo(idx int)
- func CallerName(idx int) string
- func CheckErr(err error)
- func CountChars(str string) (nc, ne, n int)
- func DblSf(msg string, slice []float64) string
- func DebugPrintCaller()
- func EnableLoggerOutToFile(levelname string)
- func Err(msg string, prm ...interface{}) error
- func FieldValueFromTagMap(e interface{}, tag string, ignoredFields ...string) (out map[string]interface{}, err error)
- func FieldValueMap(e interface{}, ignoredFields ...string) (out map[string]interface{}, err error)
- func FnExt(fn string) string
- func FnKey(fn string) string
- func GetColStr(s string, size int, isleft bool) string
- func GetErrMessage(err error) string
- func GetFieldsInfo(obj interface{}, tagname string, ignoreFields ...string) (fields, types, kinds, tags []string, err error)
- func GetSizes(h []string) []int
- func GetTags(obj interface{}, tag string) map[string]string
- func GetTypes(obj interface{}) map[string]string
- func Hstring(str string, explen int, fillchar string, align int) (rstr string)
- func Imax(a, b int) int
- func Imin(a, b int) int
- func InitLogger()
- func IntRange(args ...int) <-chan int
- func IntSf(msg string, slice []int) string
- func IsChineseChar(str string) bool
- func IsFileExist(filename string) bool
- func Isum(vals ...int) int
- func Itob(val int) bool
- func LogColorString(levelname, s string) string
- func Max(a, b float64) float64
- func Min(a, b float64) float64
- func Names(e interface{}, ignoredFields ...string) (out []string, err error)
- func NamesFromTag(e interface{}, tag string, ignoredFields ...string) (out []string, err error)
- func NewLogFile() (*os.File, error)
- func OpenFileR(fn string) (fil *os.File, err error)
- func Panic(msg string, prm ...interface{})
- func PathKey(fn string) string
- func Pf(format string, prm ...interface{})
- func PfBlue(format string, prm ...interface{})
- func PfCyan(format string, prm ...interface{})
- func PfGreen(format string, prm ...interface{})
- func PfMag(format string, prm ...interface{})
- func PfRed(format string, prm ...interface{})
- func PfWhite(format string, prm ...interface{})
- func PfYel(format string, prm ...interface{})
- func Pfblue(format string, prm ...interface{})
- func Pfblue2(format string, prm ...interface{})
- func Pfcyan(format string, prm ...interface{})
- func Pfcyan2(format string, prm ...interface{})
- func Pfdgreen(format string, prm ...interface{})
- func Pfdyel(format string, prm ...interface{})
- func Pfdyel2(format string, prm ...interface{})
- func Pfgreen(format string, prm ...interface{})
- func Pfgreen2(format string, prm ...interface{})
- func Pfgrey(format string, prm ...interface{})
- func Pfgrey2(format string, prm ...interface{})
- func Pflmag(format string, prm ...interface{})
- func Pfmag(format string, prm ...interface{})
- func Pforan(format string, prm ...interface{})
- func Pfpink(format string, prm ...interface{})
- func Pfpurple(format string, prm ...interface{})
- func Pfred(format string, prm ...interface{})
- func Pfyel(format string, prm ...interface{})
- func Pl()
- func PrintSepline(n int)
- func ReadFile(fn string) (b []byte, err error)
- func ReadLines(b []byte, cb ReadLinesCallback)
- func ReadLinesFile(fil *os.File, cb ReadLinesCallback) (oserr error)
- func RemoveAll(key string)
- func Rpad(s string, padding int) string
- func Spaces(num int) string
- func SplitFloats(str string) (res []float64)
- func SplitInts(str string) (res []int)
- func SplitKeys(keys string) []string
- func SplitSpacesQuoted(str string) (res []string)
- func SplitWithinParentheses(s string) (res []string)
- func Startfunc(fid int)
- func Stopfunc(fid int)
- func StrSf(msg string, slice []string) string
- func StrSpaces(n int) (l string)
- func StrThickLine(n int) (l string)
- func StrThinLine(n int) (l string)
- func StrValues(e interface{}, ignoredFields ...string) ([]string, error)
- func StrValuesWithFunc(e interface{}, cb ValuesCallback, ignoredFields ...string) (out []string, err error)
- func Sum(vals ...float64) float64
- func TodayFilename() string
- func Values(e interface{}, ignoredFields ...string) (out []interface{}, err error)
- func ValuesWithFunc(e interface{}, cb ValuesCallback, ignoredFields ...string) (out []interface{}, err error)
- func WriteBytesToFile(fn string, b []byte)
- func WriteFile(fn string, buffer ...*bytes.Buffer)
- type AlginedFlag
- type FuncCallerInfo
- type ReadLinesCallback
- type ValuesCallback
Constants ¶
const ( Fcstart = 101 Fcstop = 102 Fostart = 111 Fostop = 112 Ffstart = 21 Ffstop = 22 )
code of string format
Variables ¶
var ( // Sf is the alias of fmt.Sprintf Sf = fmt.Sprintf // Ff is the alias of fmt.Fprintf Ff = fmt.Fprintf )
var ( // LogColorStringFuncs maps to a serious of [*]ColorString functions with key as golog.Level LogColorStringFuncs = map[string]func(a ...interface{}) string{ "disable": fmt.Sprint, "error": errorColorStr, "warn": warnColorStr, "info": infoColorStr, "debug": debugColorStr, "debug2": debugColorStr2, "debug3": debugColorStr2, "goro": goroColorStr, } // LogfMapFuncs are the maps of Glog functions LogfMapFuncs = map[string]func(string, ...interface{}){ "error": Glog.Errorf, "warn": Glog.Warnf, "info": Glog.Infof, "debug": Glog.Debugf, "fatal": Glog.Fatalf, } // LogMapFuncs are the maps of Glog functions LogMapFuncs = map[string]func(...interface{}){ "error": Glog.Error, "warn": Glog.Warn, "info": Glog.Info, "debug": Glog.Debug, "fatal": Glog.Fatal, "print": Glog.Print, } )
var ( // Verbose activates display of messages on console Verbose = true // ColorsOn activates use of colors on console ColorsOn = true // Format is the format of message Format = map[int]string{ Fcstart: "# Start to configure. -- %q\n", Fcstop: "# Configuration has been concluded. -- %q\n", Fostart: "# Start to get case-options. -- %q\n", Fostop: "# Case-options has been concluded. -- %q\n", Ffstart: "* Function %q start.\n", Ffstop: "* Function %q stop.\n", } )
var ( Pfstart = PfCyan Pfstop = PfBlue Pfsep = Pfdyel2 Prun = PfYel Pchk = Pfgreen2 Pstat = Pfyel Plog = Pf Pinfo = Pfcyan2 Pwarn = Pforan Perr = Pfred Pdebug = Pfgreen2 )
specified function for output
var ( // Glog is a logger of golog Glog = golog.New() // Logger.Child("util") )
Functions ¶
func AlignToRight ¶
AlignToRight returns a string aligned to right
func AlignedString ¶
func AlignedString(str string, lenres int, filledChar string, alignFlag AlginedFlag) (res string)
AlignedString returns the aligned string what you want
str : the original string lenres : the length of `res` string filledChar : fill `filedChar` in the spaces of `res` string align = 1 : align at the left (default) = 0 : align at the center = -1 : align at the right
outputs
res : the aligned string
func AppendToFile ¶
AppendToFile appends data to an existent (or new) file
func ArgsTable ¶
ArgsTable prints a nice table with input arguments
Input:
title -- title of table; e.g. INPUT ARGUMENTS
data -- sets of THREE items in the following order:
description, key, value, ...
description, key, value, ...
...
description, key, value, ...
func ArgsTableN ¶
ArgsTableN prints a nice table with input arguments
Input:
title -- title of table; e.g. INPUT ARGUMENTS
heads -- heads of table; e.g. []string{ col1, col2, ... }
nledsp -- length of leading spaces in every row
data -- sets of THREE items in the following order:
column1, column2, column3, ...
column1, column2, column3, ...
...
column1, column2, column3, ...
func BytesSizeToString ¶
BytesSizeToString convert bytes to a human-readable size
func CallerInfo ¶
func CallerInfo(idx int)
CallerInfo returns the file and line positions where an error occurred
idx -- use idx=2 to get the caller of Panic
func CountChars ¶
CountChars returns the number of each other of chinses and english characters
func DebugPrintCaller ¶
func DebugPrintCaller()
DebugPrintCaller print the name of function called and calling
func EnableLoggerOutToFile ¶
func EnableLoggerOutToFile(levelname string)
EnableLoggerOutToFile enables the "Glog" out to os.Stderr and os.File
func FieldValueFromTagMap ¶
func FieldValueFromTagMap(e interface{}, tag string, ignoredFields ...string) (out map[string]interface{}, err error)
FieldValueFromTagMap returns a string to interface map that uses as key the tag name, key: tag name for the given field value: the value of the field
func FieldValueMap ¶
FieldValueMap returns a string to interface map, key: field as defined on the struct value: the value of the field
func FnExt ¶
FnExt returns the extension of a file name. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.
func GetFieldsInfo ¶
func GetFieldsInfo(obj interface{},
tagname string,
ignoreFields ...string) (fields, types, kinds, tags []string, err error)
GetFieldsInfo return information of fields
func Hstring ¶
Hstring return the formatted string what you wants. parameters
str : the original string explen : the length of 'rstr' string fillchar : fill 'fillchar' in the spaces of 'rstr' string align = 1 : align at the left (default) = 0 : align at the center = -1 : align at the right
outputs
rstr : the return string err : the error if therer are errors
func IsChineseChar ¶
IsChineseChar judges whether the chinese character exists ?
func Itob ¶
Itob converts from integer to bool
Note: only zero returns false
anything else returns true
func LogColorString ¶
LogColorString gives a colorful string w.r.t. levelname
func Names ¶
Names returns an array with all the field names (with the same order) as defined on the struct
func NamesFromTag ¶
NamesFromTag returns an array with all the tag names for each field
func PfBlue ¶
func PfBlue(format string, prm ...interface{})
PfBlue prints formatted string in high intensity blue
func PfCyan ¶
func PfCyan(format string, prm ...interface{})
PfCyan prints formatted string in high intensity cyan
func PfGreen ¶
func PfGreen(format string, prm ...interface{})
PfGreen prints formatted string in high intensity green
func PfMag ¶
func PfMag(format string, prm ...interface{})
PfMag prints formatted string in high intensity magenta
func PfRed ¶
func PfRed(format string, prm ...interface{})
PfRed prints formatted string in high intensity red
func PfWhite ¶
func PfWhite(format string, prm ...interface{})
PfWhite prints formatted string in high intensity white
func PfYel ¶
func PfYel(format string, prm ...interface{})
PfYel prints formatted string in high intensity yello
func Pfblue2 ¶
func Pfblue2(format string, prm ...interface{})
Pfblue2 prints formatted string in another shade of blue
func Pfcyan2 ¶
func Pfcyan2(format string, prm ...interface{})
Pfcyan2 prints formatted string in another shade of cyan
func Pfdgreen ¶
func Pfdgreen(format string, prm ...interface{})
Pfdgreen prints formatted string in dark green
func Pfdyel ¶
func Pfdyel(format string, prm ...interface{})
Pfdyel prints formatted string in dark yellow
func Pfdyel2 ¶
func Pfdyel2(format string, prm ...interface{})
Pfdyel2 prints formatted string in another shade of dark yellow
func Pfgreen ¶
func Pfgreen(format string, prm ...interface{})
Pfgreen prints formatted string in green
func Pfgreen2 ¶
func Pfgreen2(format string, prm ...interface{})
Pfgreen2 prints formatted string in another shade of green
func Pfgrey2 ¶
func Pfgrey2(format string, prm ...interface{})
Pfgrey2 prints formatted string in another shade of grey
func Pflmag ¶
func Pflmag(format string, prm ...interface{})
Pflmag prints formatted string in light magenta
func Pforan ¶
func Pforan(format string, prm ...interface{})
Pforan prints formatted string in orange
func Pfpurple ¶
func Pfpurple(format string, prm ...interface{})
Pfpurple prints formatted string in purple
func ReadLines ¶
func ReadLines(b []byte, cb ReadLinesCallback)
ReadLines reads lines from a []byte and calls ReadLinesCallback to process each line being read
func ReadLinesFile ¶
func ReadLinesFile(fil *os.File, cb ReadLinesCallback) (oserr error)
ReadLinesFile reads lines from a file and calls ReadLinesCallback to process each line being read
func RemoveAll ¶
func RemoveAll(key string)
RemoveAll deletes all files matching filename specified by key (be careful)
func SplitFloats ¶
SplitFloats splits space-separated float numbers
func SplitSpacesQuoted ¶
SplitSpacesQuoted splits string with quoted substrings. e.g. " a,b, 'c', \"d\" "
func SplitWithinParentheses ¶
SplitWithinParentheses extracts arguments (substrings) within brackets e.g.: "(arg1, (arg2.1, arg2.2), arg3, arg4, (arg5.1,arg5.2, arg5.3 ) )"
func StrThickLine ¶
StrThickLine returns a thick line (using '=')
func StrValuesWithFunc ¶
func StrValuesWithFunc(e interface{},
cb ValuesCallback,
ignoredFields ...string) (out []string, err error)
StrValuesWithFunc returns an interface array with all the string-values
func TodayFilename ¶
func TodayFilename() string
TodayFilename get a filename based on the date, file logs works that way the most times but these are just a sugar.
func ValuesWithFunc ¶
func ValuesWithFunc(e interface{},
cb ValuesCallback,
ignoredFields ...string) (out []interface{}, err error)
ValuesWithFunc returns an interface array with all the values
func WriteBytesToFile ¶
WriteBytesToFile writes slice of bytes to a new file
Types ¶
type AlginedFlag ¶
type AlginedFlag int8
AlginedFlag is the type to assign align-format
const ( AlginedLeft AlginedFlag = iota AlginedMiddle AlignedRight )
Align format
type FuncCallerInfo ¶
FuncCallerInfo describes the information of callers of function
func RetrieveCallerInfo ¶
func RetrieveCallerInfo(idx int) *FuncCallerInfo
RetrieveCallerInfo retrieve the information of callers of function
type ReadLinesCallback ¶
ReadLinesCallback is used in ReadLines to process line by line during reading of a file
type ValuesCallback ¶
type ValuesCallback func(f reflect.StructField, v interface{}) (value interface{}, isIgnored bool)
ValuesCallback is used in (Str)ValuesWithFunc to process line by line during retriving of
a field-value example:
var cb ValuesCallback = func(fieldName string, v interface{}) (value interface{}, isIgnored bool) { switch fieldName { case "Model", "Details":
value, isIgnored = nil, true
case "UINumber":
a := v.(string)
value, isIgnored = interface{}(a[0:2]+"-"+a[2:]), false
case "Date":
value, isIgnored = interface{}(v.(time.Time).Format(ShortDateFormat)), false
case "Total":
value, isIgnored = interface{}(fmt.Sprintf("%.1f", v.(float64))), false
}
default:
value, isIgnored = v, false
return value, isIgnored }