initialize the validate Settings no need to use sync.once

This commit is contained in:
daheige 2021-06-05 13:33:50 +08:00
parent e5311338d1
commit 06f332fadf

View File

@ -8,13 +8,11 @@ import (
"fmt"
"reflect"
"strings"
"sync"
"github.com/go-playground/validator/v10"
)
type defaultValidator struct {
once sync.Once
validate *validator.Validate
}
@ -77,9 +75,10 @@ func (v *defaultValidator) Engine() interface{} {
return v.validate
}
// lazyInit initialize the validate Settings, no need to use sync.once
func (v *defaultValidator) lazyInit() {
v.once.Do(func() {
if v.validate == nil {
v.validate = validator.New()
v.validate.SetTagName("binding")
})
}
}