summaryrefslogtreecommitdiff
path: root/vendor/github.com/gin-gonic/gin/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gin-gonic/gin/utils.go')
-rw-r--r--vendor/github.com/gin-gonic/gin/utils.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/vendor/github.com/gin-gonic/gin/utils.go b/vendor/github.com/gin-gonic/gin/utils.go
index c32f0eeb0..4021a2ab4 100644
--- a/vendor/github.com/gin-gonic/gin/utils.go
+++ b/vendor/github.com/gin-gonic/gin/utils.go
@@ -1,4 +1,4 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
+// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
@@ -12,13 +12,14 @@ import (
"reflect"
"runtime"
"strings"
+ "unicode"
)
// BindKey indicates a default bind key.
const BindKey = "_gin-gonic/gin/bindkey"
// Bind is a helper function for given interface object and returns a Gin middleware.
-func Bind(val interface{}) HandlerFunc {
+func Bind(val any) HandlerFunc {
value := reflect.ValueOf(val)
if value.Kind() == reflect.Ptr {
panic(`Bind struct can not be a pointer. Example:
@@ -50,7 +51,7 @@ func WrapH(h http.Handler) HandlerFunc {
}
// H is a shortcut for map[string]interface{}
-type H map[string]interface{}
+type H map[string]any
// MarshalXML allows type H to be used with xml.Marshal.
func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
@@ -89,7 +90,7 @@ func filterFlags(content string) string {
return content
}
-func chooseData(custom, wildcard interface{}) interface{} {
+func chooseData(custom, wildcard any) any {
if custom != nil {
return custom
}
@@ -120,7 +121,7 @@ func lastChar(str string) uint8 {
return str[len(str)-1]
}
-func nameOfFunction(f interface{}) string {
+func nameOfFunction(f any) string {
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
}
@@ -151,3 +152,13 @@ func resolveAddress(addr []string) string {
panic("too many parameters")
}
}
+
+// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters
+func isASCII(s string) bool {
+ for i := 0; i < len(s); i++ {
+ if s[i] > unicode.MaxASCII {
+ return false
+ }
+ }
+ return true
+}