Skip to content

andrietri/go-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:"andrietrilaksono@gmail.com" 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

About

Go helper for your go application needs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages