mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: add recursive nameservers settings for dns challenge #372
This commit is contained in:
parent
d3e9d92750
commit
7be4a70824
22 changed files with 4517 additions and 3498 deletions
26
api/api.go
26
api/api.go
|
@ -4,9 +4,10 @@ import (
|
|||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
val "github.com/go-playground/validator/v10"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -27,7 +28,7 @@ func BindAndValid(c *gin.Context, target interface{}) bool {
|
|||
if err != nil {
|
||||
logger.Error("bind err", err)
|
||||
|
||||
var verrs val.ValidationErrors
|
||||
var verrs validator.ValidationErrors
|
||||
ok := errors.As(err, &verrs)
|
||||
|
||||
if !ok {
|
||||
|
@ -44,7 +45,7 @@ func BindAndValid(c *gin.Context, target interface{}) bool {
|
|||
var path []string
|
||||
|
||||
namespace := strings.Split(value.StructNamespace(), ".")
|
||||
logger.Debug(t.Name(), namespace)
|
||||
// logger.Debug(t.Name(), namespace)
|
||||
if t.Name() != "" && len(namespace) > 1 {
|
||||
namespace = namespace[1:]
|
||||
}
|
||||
|
@ -67,13 +68,30 @@ func BindAndValid(c *gin.Context, target interface{}) bool {
|
|||
|
||||
// findField recursively finds the field in a nested struct
|
||||
func getJsonPath(t reflect.Type, fields []string, path *[]string) {
|
||||
f, ok := t.FieldByName(fields[0])
|
||||
field := fields[0]
|
||||
// used in case of array
|
||||
var index string
|
||||
if field[len(field)-1] == ']' {
|
||||
re := regexp.MustCompile(`(\w+)\[(\d+)\]`)
|
||||
matches := re.FindStringSubmatch(field)
|
||||
|
||||
if len(matches) > 2 {
|
||||
field = matches[1]
|
||||
index = matches[2]
|
||||
}
|
||||
}
|
||||
|
||||
f, ok := t.FieldByName(field)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
*path = append(*path, f.Tag.Get("json"))
|
||||
|
||||
if index != "" {
|
||||
*path = append(*path, index)
|
||||
}
|
||||
|
||||
if len(fields) > 1 {
|
||||
subFields := fields[1:]
|
||||
getJsonPath(f.Type, subFields, path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue