Categorygithub.com/andrietri/go-helper
repositorypackage
1.0.2
Repository: https://github.com/andrietri/go-helper.git
Documentation: pkg.go.dev

# README

go-helper

go helper for your go application needs

Installation

go get github.com/andrietri/go-helper

Usage

Validation Struct

import "github.com/andrietri/go-helper"

// struct
type Request struct {
	Email  string `json:"email" example:"[email protected]" validate:"required" msg:"error_invalid_email"`
	Name string `json:"name" example:"andrie" validate:"required" msg:"error_invalid_name"`
}

var RequestErrorMessage = map[string]string{
	"error_invalid_email":  "email is required",
	"error_invalid_name":  "name is required",
}

func main() {
    var (
        request Request
    )

    errorMessage := helper.ValidateStruct(request, RequestErrorMessage)

    a, _ := json.MarshalIndent(errorMessage, "", "\t")
	fmt.Print(string(a))
}
{
	"email": "email is required",
	"name": "name is required"
}

Contributing

pull requests are welcome

License

MIT