gomu is a library for handling of nullable values and unassigned parameter.
Make sure that Go is installed on your computer. Type the following command in your terminal:
go get gopkg.in/hapoon/gomu.v1
After it the package is ready to use.
Add following line in your *.go
file:
import "gopkg.in/hapoon/gomu.v1"
Nullable string.
If JSON value is null, String.Null is true. If JSON key is not assigned, String.Valid is false.
Nullable int64.
If JSON value is null, Int.Null is true. If JSON key is not assigned, Int.Valid is false.
Nullable bool.
If JSON value is null, Bool.Null is true. If JSON key is not assigned, Bool.Valid is false.
Nullable Time.
If JSON value is null, Time.Null is true. If JSON key is not assigned, Time.Valid is false.
type exampleStruct struct {
Name String `valid:"stringlength(1|10)"`
URL String `valid:"requrl"`
}
example := exampleStruct{
Name: "sample name",
URL: "https://sample.com/top/",
}
result, err := gomu.Validate(example)
if !result {
if err != nil {
println("error: " + err.Error())
}
}