Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error: concurrent map writes #485

Open
mycode65678 opened this issue Jan 1, 2023 · 0 comments
Open

fatal error: concurrent map writes #485

mycode65678 opened this issue Jan 1, 2023 · 0 comments

Comments

@mycode65678
Copy link

The gin framework I use will cause fatal errors when there are too many concurrent accesses.

fatal error: concurrent map writes


// implements the binding.StructValidator
type customValidator struct{}

func (c *customValidator) ValidateStruct(ptr interface{}) error {

	govalidator.ParamTagMap["google"] = govalidator.ParamValidator(func(str string, params ...string) bool {
		a.Log.Debug("customGoogle ParamTagMap")
		return false
	})
	govalidator.ParamTagMap["google"] = govalidator.ParamValidator(func(str string, params ...string) bool {
		a.Log.Debug("customGoogle ParamTagMap")
		return false
	})

	// Add your own struct validation tags with parameter
	govalidator.ParamTagMap["compared"] = govalidator.ParamValidator(func(str string, params ...string) bool {
		res := reflect.ValueOf(ptr).Elem().FieldByName(params[0]).Interface().(string)
		return str == res
	})

	//register the regex for validate
	govalidator.ParamTagRegexMap["compared"] = regexp.MustCompile("^compared\\((\\w+)\\)$")
	if _, err := govalidator.ValidateStruct(ptr); err != nil {
		a.Log.Errorf("ValidateStruct err:%v", err)
		return err
	}
	return nil
}

func (c *customValidator) Engine() interface{} {
	return nil
}

func main(){
	binding.Validator = &customValidator{}
        r := gin.Default()
	r.Run(":9191")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant