Skip to content

Files

76 lines (51 loc) · 1.69 KB

README.md

File metadata and controls

76 lines (51 loc) · 1.69 KB

gomu

GoDoc Build Status Coverage Status MIT License

gomu is a library for handling of nullable values and unassigned parameter.

Installation

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"

Usage

String

Nullable string.

If JSON value is null, String.Null is true. If JSON key is not assigned, String.Valid is false.

Int

Nullable int64.

If JSON value is null, Int.Null is true. If JSON key is not assigned, Int.Valid is false.

Bool

Nullable bool.

If JSON value is null, Bool.Null is true. If JSON key is not assigned, Bool.Valid is false.

Time

Nullable Time.

If JSON value is null, Time.Null is true. If JSON key is not assigned, Time.Valid is false.

Validate

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())
    }
}

License

MIT License