Documentation ¶
Overview ¶
This is a wrapper of standard http package, exposing out-of-the-box flags like proxy, timeout, json handling.
Index ¶
- Variables
- func Check(err error)
- func CronTick(interval time.Duration) <-chan struct{}
- func DCheck(err error)
- func DedupStrings(slice []string) []string
- func FetchData(path string) ([]byte, error)
- func FetchDataWithContext(ctx context.Context, path string) ([]byte, error)
- func FetchJson(path string, resp interface{}) error
- func FetchJsonWithContext(ctx context.Context, path string, resp interface{}) error
- func FetchXml(path string, resp interface{}) error
- func FetchXmlWithContext(ctx context.Context, path string, resp interface{}) error
- func GenMask(slice []string) map[string]bool
- func Get(url string) (*http.Response, error)
- func GetDownloadClient() *http.Client
- func GetFuncName(i interface{}) string
- func GetNow() time.Time
- func GetWithContext(ctx context.Context, url string) (*http.Response, error)
- func Init()
- func IsDebuging() bool
- func Jsonify(v interface{}) string
- func LogDebug(v ...interface{})
- func LogDebugf(msg string, v ...interface{})
- func LogError(v ...interface{})
- func LogErrorDetail(v ...interface{})
- func LogErrorf(msg string, v ...interface{})
- func LogFatal(v ...interface{})
- func LogFatalf(msg string, v ...interface{})
- func LogInfo(v ...interface{})
- func LogInfof(msg string, v ...interface{})
- func MatchString(pattern, s string) (matched bool, err error)
- func NewError(v ...interface{}) error
- func OutputHttpJson(w http.ResponseWriter, resp interface{})
- func OutputHttpOk(w http.ResponseWriter)
- func PkgInit(f func())
- func PostForm(uri string, data map[string]string) (*http.Response, error)
- func PostFormWithContext(ctx context.Context, uri string, data map[string]string) (*http.Response, error)
- func PostJson(url string, data interface{}) (*http.Response, error)
- func PostJsonWithContext(ctx context.Context, url string, data interface{}) (*http.Response, error)
- func PrintJson(v interface{})
- func ReverseStringSlice(slice []string) []string
- func SprintHTML(htmlTmpl string, data interface{}) string
- func Sprintt(textTmpl string, data interface{}) string
- func StringSliceContains(slice []string, s string) bool
- func StringSliceIndex(slice []string, s string) int
- func ToTitle(s string) string
- type Monitor
- type OrderByValue
- type Regexp
- type StringIntPair
- type Var
Constants ¶
This section is empty.
Variables ¶
var (
ChinaTimezone = time.FixedZone("Asia/Shanghai", 8*60*60) // In case the deploying machine is not in +8 Timezone.
)
Functions ¶
func Check ¶
func Check(err error)
Check provide a quick way to check unexpected errors that should never happen. It's basically an assertion that once err != nil, fatal panic is thrown.
func CronTick ¶
CronTick returns a channel which trigger every *interval* time. It's almost the same as time.Tick, except it align the start time to integer. For example, an interval of 10 minutes, will start in xx:00:00, xx:10:00, etc.
func DCheck ¶
func DCheck(err error)
Check provide a quick way to check unexpected errors that should never happen. It's almost the same as Check(), except only in debug mode will throw panic.
func DedupStrings ¶
func FetchData ¶
FetchData is a helper function to load local/remote data in the same function. Local: goutils.FetchData("/absolute/path/to/file") Remote: goutils.FetchData("https://www.google.com") Also, it's integrated with proxy in flags. TODO(yuheng): Allow more options, while keeping easy use.
func FetchDataWithContext ¶
func FetchJsonWithContext ¶
func FetchXmlWithContext ¶
func GetDownloadClient ¶
func GetFuncName ¶
func GetFuncName(i interface{}) string
GetFuncName provides shortcut to print the name of any function.
func Init ¶
func Init()
Init need to be execute in the beginning of main() to get PkgInit() to work. NOTE: It already called flag.Parse() alternative method. No need to call flag.Parse() any more.
func Jsonify ¶
func Jsonify(v interface{}) string
Jsonify provides shortcut to return an json format string of any varible.
func LogDebug ¶
func LogDebug(v ...interface{})
LogDebug prints info to standard output with [DEBUG] prefix in debug mode.
func LogDebugf ¶
func LogDebugf(msg string, v ...interface{})
Same as LogDebug, except accepting formating info.
func LogError ¶
func LogError(v ...interface{})
LogError prints error to error output with [ERROR] prefix.
func LogErrorDetail ¶
func LogErrorDetail(v ...interface{})
func LogErrorf ¶
func LogErrorf(msg string, v ...interface{})
Same as LogError, except accepting formating info.
func LogFatal ¶
func LogFatal(v ...interface{})
LogFatal prints error to error output with [FATAL] prefix, and terminate the application.
func LogFatalf ¶
func LogFatalf(msg string, v ...interface{})
Same as LogFatal, except accepting formating info.
func LogInfo ¶
func LogInfo(v ...interface{})
LogInfo prints info to standard output with [INFO] prefix.
func LogInfof ¶
func LogInfof(msg string, v ...interface{})
Same as LogInfo, except accepting formating info.
func MatchString ¶
MatchString is the same as regexp.MatchString(), except it use the cached version of compiled pattern.
func NewError ¶
func NewError(v ...interface{}) error
NewError returns an error composed like fmt.Sprintf().
func OutputHttpJson ¶
func OutputHttpJson(w http.ResponseWriter, resp interface{})
func OutputHttpOk ¶
func OutputHttpOk(w http.ResponseWriter)
func PkgInit ¶
func PkgInit(f func())
PkgInit is a deferred helper to initialize the package enviornment varible AFTER flags are set. Example usage: >package.go
func init() { utils.PkgInit(func() { // Your initialization codes here... All flags are available. }) }
>main.go
func main() { utils.Init() // Other codes ... }
func PostFormWithContext ¶
func PostJsonWithContext ¶
func PrintJson ¶
func PrintJson(v interface{})
PrintJson outputs any varible in Json format to console. Useful for debuging.
func ReverseStringSlice ¶
func SprintHTML ¶
func StringSliceContains ¶
StringSliceContains determines whether a string is contained in another slice. NOTE: This is just a convinient helper. It's computing time complexity is O(N), which may be a performance trap.
func StringSliceIndex ¶
Types ¶
type Monitor ¶
Monitor is a polling helper to get new updates from external source, by comparing the last modified field. Example Usage:
m := NewMonitor(time.Now(), time.Minute) for { since := m.Next() results := dbQuery(table.updated_at, "$gt", since) for _, result := range results { m.Update(result.LastModified) ... Remaining processing } }
type OrderByValue ¶
type OrderByValue []StringIntPair
func (OrderByValue) Len ¶
func (slice OrderByValue) Len() int
func (OrderByValue) Less ¶
func (slice OrderByValue) Less(i, j int) bool
func (OrderByValue) Swap ¶
func (slice OrderByValue) Swap(i, j int)
type Regexp ¶
func CompileRegexp ¶
CompileRegexp is the same as regexp.Compile(), except it cached all the compiled patterns for performance.
type StringIntPair ¶
func IterStringIntMap ¶
func IterStringIntMap(in map[string]int) []StringIntPair
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package beanstalkd is a higher level wrapper to utilize beanstalkd as a simple message queue.
|
Package beanstalkd is a higher level wrapper to utilize beanstalkd as a simple message queue. |
Package cache provides MemCache as a TTL based simple cache in memory.
|
Package cache provides MemCache as a TTL based simple cache in memory. |
Package csv provides CsvReader and CsvWriter to process csv format file in the struct declaration style.
|
Package csv provides CsvReader and CsvWriter to process csv format file in the struct declaration style. |
Package flags provide a global flags cache and extends types of flags.
|
Package flags provide a global flags cache and extends types of flags. |
Package mongo provides handful wrapper to access and/or modify the mongo database.
|
Package mongo provides handful wrapper to access and/or modify the mongo database. |
Package presto provides struct declaration style wrapper to access presto result.
|
Package presto provides struct declaration style wrapper to access presto result. |
This package provide a simple way to sample steam data.
|
This package provide a simple way to sample steam data. |
Package sort provides ranking method to easily sort a slice.
|
Package sort provides ranking method to easily sort a slice. |