Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 2.16 KB

README.md

File metadata and controls

64 lines (43 loc) · 2.16 KB

goutils

goutils is a set of common utilities for the Go language

CircleCI Code Climate Test Coverage Issue Count

This library provides utilities for validation and convertion of types. Seedocumentation

Validators

To perform validations on a type you first need a validator

myValidator := validators.String("qwerty")

Simple validations can be done using the functions prefixed with IsXXX or HasXXX. These functions returns a bool. This is most useful when you need to do a single validation validation

myValidator.IsHex() // false

Validators can also be chained to do multiple validations in one go. Use the same functions as above, but without the IsXXX or HasXXX prefix and end with the special HasErrors() function

myValidator.Hex().
	MaxLen(5).
	MinLen(2).
	HasErrors() // true

The check the results of the validations use the helper functions from the validators.Validator type

myValidator.FirstError() // First registered error (Hex)
myValidator.Errors()     // All errors [Hex, MinLen]

Implementations

goutils currently has validation implementations for the following types:

  • string
  • url.URL

Planned validators

  • int (8/16/32/64)
  • uint (8/16/32/64)
  • float (32/64)

More validation functions and types to come.

Converters

Convert from string to time.Time:

fmt.Println(converters.String("1502835623824559499").MustTimeFromNsec())
fmt.Println(converters.String("1502835623").MustTimeFromSec())

Contributions

Feature requests, feedback and pull requests welcome!