Documentation ¶
Index ¶
- Variables
- func ExitWithMsg(msg interface{}, value ...interface{})
- func FileServer(dir http.Dir) http.Handler
- func GOPATH() []string
- func GetAbsURL(req *http.Request) url.URL
- func HumanizeString(str string) string
- func Indirect(v reflect.Value) reflect.Value
- 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 ParamsMatch(source string, pth string) (url.Values, string, bool)
- func ParseTagOption(str string) map[string]string
- func PatchURL(originalURL string, params ...interface{}) (patchedURL string, err error)
- func SafeJoin(paths ...string) (string, error)
- func SetCookie(cookie http.Cookie, context *qor.Context)
- func SliceUniq(s []string) []string
- func SortFormKeys(strs []string)
- 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
- type ClosingReadSeeker
- type ContextKey
Constants ¶
This section is empty.
Variables ¶
var AppRoot, _ = os.Getwd()
AppRoot app root path
var FormatTime = func(date time.Time, format string, context *qor.Context) string {
return date.Format(format)
}
FormatTime format time to string Overwrite the default logic with
utils.FormatTime = func(time time.Time, format string, context *qor.Context) string { // .... }
var GetDBFromRequest = func(req *http.Request) *gorm.DB { db := req.Context().Value(ContextDBName) if tx, ok := db.(*gorm.DB); ok { return tx } return nil }
GetDBFromRequest get database from request
var GetLocale = func(context *qor.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 request, cookie, after get the locale, will write the locale to the cookie if possible Overwrite the default logic with
utils.GetLocale = func(context *qor.Context) string { // .... }
var HTMLSanitizer = bluemonday.UGCPolicy()
HTMLSanitizer html sanitizer to avoid XSS
var ParseTime = func(timeStr string, context *qor.Context) (t time.Time, err error) { if t, err = now.Parse(timeStr); err != nil { timeSlice := strings.Split(timeStr, "-") if len(timeSlice[0]) == 2 { tmp := timeSlice[0] timeSlice[0] = timeSlice[2] timeSlice[2] = tmp timeStr = strings.Join(timeSlice, "-") t, err = now.Parse(timeStr) } } return }
ParseTime parse time from string Overwrite the default logic with
utils.ParseTime = func(timeStr string, context *qor.Context) (time.Time, error) { // .... }
Functions ¶
func ExitWithMsg ¶
func ExitWithMsg(msg interface{}, value ...interface{})
ExitWithMsg debug error messages and print stack
func FileServer ¶
FileServer file server that disabled file listing
func GetAbsURL ¶
GetAbsURL get absolute URL from request, refer: https://stackoverflow.com/questions/6899069/why-are-request-url-host-and-scheme-blank-in-the-development-server
func HumanizeString ¶
HumanizeString Humanize separates string based on capitalizd letters e.g. "OrderItem" -> "Order Item"
func JoinURL ¶
JoinURL updates the path part of the request url.
JoinURL("google.com", "admin") => "google.com/admin" JoinURL("google.com?q=keyword", "admin") => "google.com/admin?q=keyword"
func ParamsMatch ¶
ParamsMatch match string by param
func ParseTagOption ¶
ParseTagOption parse tag options to hash
func PatchURL ¶
PatchURL updates the query part of the request url.
PatchURL("google.com","key","value") => "google.com?key=value"
func SafeJoin ¶
SafeJoin safe join https://snyk.io/research/zip-slip-vulnerability#go
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 array from value, will ignore blank string to convert it 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 separates words (by uppercase letters) with underscores in a string, also downcase it e.g. ToParamString -> to_param_string, To ParamString -> to_param_string
Types ¶
type ClosingReadSeeker ¶
type ClosingReadSeeker struct {
io.ReadSeeker
}
ClosingReadSeeker implement Closer interface for ReadSeeker
func (ClosingReadSeeker) Close ¶
func (ClosingReadSeeker) Close() error
Close implement Closer interface for Buffer
type ContextKey ¶
type ContextKey string
ContextKey defined type used for context's key
var ContextDBName ContextKey = "ContextDB"
ContextDBName db name used for context