The validationMessageHelper
package provides utility functions to handle validation errors returned by the Go Playground's validator library. It simplifies the process of generating descriptive error messages for validation failures.
- Easily convert validation errors into a map of field-specific error messages.
- Support for common validation tags such as
email
,required
,min
, andmax
. - Customizable error messages to suit your application's needs.
You can install the package using go get
:
go get -u github.com/ilhamgepe/validationMessageHelper
package main
import (
"fmt"
"github.com/ilhamgepe/validationMessageHelper"
)
func main() {
// Example usage
err := validate.Struct(mystruct)
if err != nil {
errors := validationMessageHelper.GenerateMessage(err)
fmt.Println(errors)
// or return as a response
// since GenerateMessage() only return map[string]string
}
}
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.
This package is licensed under the MIT License.