mirror of
https://github.com/astaxie/beego.git
synced 2025-07-07 01:50:19 +00:00
golint templatefunc
This commit is contained in:
@ -44,8 +44,8 @@ func Substr(s string, start, length int) string {
|
||||
return string(bt[start:end])
|
||||
}
|
||||
|
||||
// Html2str returns escaping text convert from html.
|
||||
func Html2str(html string) string {
|
||||
// HTML2str returns escaping text convert from html.
|
||||
func HTML2str(html string) string {
|
||||
src := string(html)
|
||||
|
||||
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
|
||||
@ -115,7 +115,7 @@ var datePatterns = []string{
|
||||
"r", time.RFC1123Z,
|
||||
}
|
||||
|
||||
// Parse Date use PHP time format.
|
||||
// DateParse Parse Date use PHP time format.
|
||||
func DateParse(dateString, format string) (time.Time, error) {
|
||||
replacer := strings.NewReplacer(datePatterns...)
|
||||
format = replacer.Replace(format)
|
||||
@ -139,14 +139,17 @@ func Compare(a, b interface{}) (equal bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// CompareNot !Compare
|
||||
func CompareNot(a, b interface{}) (equal bool) {
|
||||
return !Compare(a, b)
|
||||
}
|
||||
|
||||
func NotNil(a interface{}) (is_nil bool) {
|
||||
// NotNil the same as CompareNot
|
||||
func NotNil(a interface{}) (isNil bool) {
|
||||
return CompareNot(a, nil)
|
||||
}
|
||||
|
||||
// Config get the Appconfig
|
||||
func Config(returnType, key string, defaultVal interface{}) (value interface{}, err error) {
|
||||
switch returnType {
|
||||
case "String":
|
||||
@ -162,12 +165,12 @@ func Config(returnType, key string, defaultVal interface{}) (value interface{},
|
||||
case "DIY":
|
||||
value, err = AppConfig.DIY(key)
|
||||
default:
|
||||
err = errors.New("Config keys must be of type String, Bool, Int, Int64, Float, or DIY!")
|
||||
err = errors.New("Config keys must be of type String, Bool, Int, Int64, Float, or DIY")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if reflect.TypeOf(returnType) != reflect.TypeOf(defaultVal) {
|
||||
err = errors.New("defaultVal type does not match returnType!")
|
||||
err = errors.New("defaultVal type does not match returnType")
|
||||
} else {
|
||||
value, err = defaultVal, nil
|
||||
}
|
||||
@ -184,7 +187,7 @@ func Config(returnType, key string, defaultVal interface{}) (value interface{},
|
||||
return
|
||||
}
|
||||
|
||||
// Convert string to template.HTML type.
|
||||
// Str2html Convert string to template.HTML type.
|
||||
func Str2html(raw string) template.HTML {
|
||||
return template.HTML(raw)
|
||||
}
|
||||
@ -258,7 +261,7 @@ func URLFor(endpoint string, values ...interface{}) string {
|
||||
return BeeApp.Handlers.URLFor(endpoint, values...)
|
||||
}
|
||||
|
||||
// returns script tag with src string.
|
||||
// AssetsJs returns script tag with src string.
|
||||
func AssetsJs(src string) template.HTML {
|
||||
text := string(src)
|
||||
|
||||
@ -267,8 +270,8 @@ func AssetsJs(src string) template.HTML {
|
||||
return template.HTML(text)
|
||||
}
|
||||
|
||||
// returns stylesheet link tag with src string.
|
||||
func AssetsCss(src string) template.HTML {
|
||||
// AssetsCSS returns stylesheet link tag with src string.
|
||||
func AssetsCSS(src string) template.HTML {
|
||||
text := string(src)
|
||||
|
||||
text = "<link href=\"" + src + "\" rel=\"stylesheet\" />"
|
||||
@ -276,7 +279,7 @@ func AssetsCss(src string) template.HTML {
|
||||
return template.HTML(text)
|
||||
}
|
||||
|
||||
// parse form values to struct via tag.
|
||||
// ParseForm will parse form values to struct via tag.
|
||||
func ParseForm(form url.Values, obj interface{}) error {
|
||||
objT := reflect.TypeOf(obj)
|
||||
objV := reflect.ValueOf(obj)
|
||||
@ -398,7 +401,7 @@ var unKind = map[reflect.Kind]bool{
|
||||
reflect.UnsafePointer: true,
|
||||
}
|
||||
|
||||
// render object to form html.
|
||||
// RenderForm will render object to form html.
|
||||
// obj must be a struct pointer.
|
||||
func RenderForm(obj interface{}) template.HTML {
|
||||
objT := reflect.TypeOf(obj)
|
||||
@ -651,9 +654,7 @@ func ge(arg1, arg2 interface{}) (bool, error) {
|
||||
return !lessThan, nil
|
||||
}
|
||||
|
||||
// go1.2 added template funcs. end
|
||||
|
||||
// getting value from map by keys
|
||||
// MapGet getting value from map by keys
|
||||
// usage:
|
||||
// Data["m"] = map[string]interface{} {
|
||||
// "a": 1,
|
||||
@ -719,14 +720,11 @@ func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) {
|
||||
// if there is more keys, handle this recursively
|
||||
if len(arg2) > 1 {
|
||||
return MapGet(result, arg2[1:]...)
|
||||
} else {
|
||||
return result, nil
|
||||
}
|
||||
} else {
|
||||
return nil, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
} else {
|
||||
return nil, nil
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user