Skip to content

Commit

Permalink
feat: add recursive nameservers settings for dns challenge #372
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed May 4, 2024
1 parent d3e9d92 commit 7be4a70
Show file tree
Hide file tree
Showing 22 changed files with 4,518 additions and 3,499 deletions.
26 changes: 22 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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:]
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@
"vite-svg-loader": "^5.1.0",
"vue-tsc": "^1.8.27"
},
"packageManager": "pnpm@8.15.5+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589"
"packageManager": "pnpm@9.0.6+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3"
}
Loading

0 comments on commit 7be4a70

Please sign in to comment.