|
|
@ -4,6 +4,7 @@ import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"crypto/sha256" |
|
|
|
"crypto/sha256" |
|
|
|
|
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
@ -166,6 +167,7 @@ var ( |
|
|
|
"html_encoded": isHTMLEncoded, |
|
|
|
"html_encoded": isHTMLEncoded, |
|
|
|
"url_encoded": isURLEncoded, |
|
|
|
"url_encoded": isURLEncoded, |
|
|
|
"dir": isDir, |
|
|
|
"dir": isDir, |
|
|
|
|
|
|
|
"json": isJSON, |
|
|
|
"hostname_port": isHostnamePort, |
|
|
|
"hostname_port": isHostnamePort, |
|
|
|
"lowercase": isLowercase, |
|
|
|
"lowercase": isLowercase, |
|
|
|
"uppercase": isUppercase, |
|
|
|
"uppercase": isUppercase, |
|
|
@ -2011,6 +2013,17 @@ func isDir(fl FieldLevel) bool { |
|
|
|
panic(fmt.Sprintf("Bad field type %T", field.Interface())) |
|
|
|
panic(fmt.Sprintf("Bad field type %T", field.Interface())) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// isJSON is the validation function for validating if the current field's value is a valid json string.
|
|
|
|
|
|
|
|
func isJSON(fl FieldLevel) bool { |
|
|
|
|
|
|
|
field := fl.Field() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if field.Kind() == reflect.String { |
|
|
|
|
|
|
|
val := field.String() |
|
|
|
|
|
|
|
return json.Valid([]byte(val)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
panic(fmt.Sprintf("Bad field type %T", field.Interface())) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// isHostnamePort validates a <dns>:<port> combination for fields typically used for socket address.
|
|
|
|
// isHostnamePort validates a <dns>:<port> combination for fields typically used for socket address.
|
|
|
|
func isHostnamePort(fl FieldLevel) bool { |
|
|
|
func isHostnamePort(fl FieldLevel) bool { |
|
|
|
val := fl.Field().String() |
|
|
|
val := fl.Field().String() |
|
|
|