Documentation ¶
Index ¶
- Variables
- func ExitWithMsg(msg interface{}, value ...interface{})
- func FileServer(dir http.Dir) http.Handler
- func HumanizeString(str string) string
- func JoinURL(originalURL string, paths ...interface{}) (joinedURL string, err error)
- func ModelType(value interface{}) reflect.Type
- func NewValue(t reflect.Type) (v reflect.Value)
- func ParseTagOption(str string) map[string]string
- func PatchURL(originalURL string, params ...interface{}) (patchedURL string, err error)
- func SetCookie(cookie http.Cookie, context *TM_EC.Context)
- func Stringify(object interface{}) string
- func ToArray(value interface{}) (values []string)
- func ToFloat(value interface{}) float64
- func ToInt(value interface{}) int64
- func ToParamString(str string) string
- func ToString(value interface{}) string
- func ToUInt(value interface{}) uint64
Constants ¶
This section is empty.
Variables ¶
var FormatTime = func(date time.Time, format string, context *TM_EC.Context) string {
return date.Format(format)
}
'FormatTime' format time to string Overwrite the default logic with
utils.FormatTime = func(date time.Time, format string, context *TM_EC.Context) string { // ..... }
var GetLocale = func(context *TM_EC.Context) string { if locale := context.Request.Header.Get("Locale"); locale != "" { return locale } if locale := context.Request.URL.Query().Get("locale"); locale != "" { if context.Writer != nil { context.Request.Header.Set("Locale", locale) SetCookie(http.Cookie{Name: "locale", Value: locale, Expires: time.Now().AddDate(1, 0, 0)}, context) } return locale } if locale, err := context.Request.Cookie("locale"); err == nil { return locale.Value } return "" }
'GetLocale' get locale from reqeust, cookie, after get the locale, will write the locale to the cookie if possible Overwrite the default logic with
utils.GetLocal = func(context *TM_EC.Context) string { // ..... }
var HTMLSanitizer = bluemonday.UGCPolicy()
var ParseTime = func(timeStr string, context *TM_EC.Context) (time.Time, error) { return now.Parse(timeStr) }
'ParseTime' parse time from string Overwrite the default logic with
utils.ParseTime = func(timeStr string, context *TM_EC.Context) (time.Time, error) { // ..... }
Functions ¶
func ExitWithMsg ¶
func ExitWithMsg(msg interface{}, value ...interface{})
'ExistWithMsg' debug error messages and print stack
func FileServer ¶
'FileServer' file server that disabled file listing
func HumanizeString ¶
'HumanizeString' humanize separates string based on capitalize letters e.g. "OrderItem" -> "Order Item"
func JoinURL ¶
'JoinURL' updates the path part of the request url e.g. JoinURL("google.com", "admin") => "google.com/admin" e.g. JoinURL("google.com?q=keyword", "admin") => "google.com/admin?q=keyword"
func ParseTagOption ¶
'ParseTagOption' parse tag options to hash
func PatchURL ¶
'PatchURL' updates thr query part of the request url. e.g. PatchURL("google.com","key","value") -> "google.com?key=value"
func Stringify ¶
func Stringify(object interface{}) string
'Stringify' stringify any data, if it is a struct, will try to use its Name, title, Code field, else will use its primary key
func ToArray ¶
func ToArray(value interface{}) (values []string)
'ToArray' get a array from value, will ignore blank string to convert is to array
func ToFloat ¶
func ToFloat(value interface{}) float64
'ToFloat' get float from value, if passed value is empty string ,result will be 0
func ToInt ¶
func ToInt(value interface{}) int64
'ToInt' get int from value, if passed value is empty string ,result will be 0
func ToParamString ¶
'ToParamString' replaces spaces and sparaters words (by uppercase letters) with underscores in a string, also downcase it e.g. "ToParamString" -> "to_param_string", "To ParamString" -> "to_param_string"
Types ¶
This section is empty.