Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.38 KB

README.md

File metadata and controls

48 lines (32 loc) · 1.38 KB

cast

Build Status Coverage Status GoDoc

Cast is a package that can cast different go types to other types. You don't need to be worried about performance because this package doesn't use reflect package so it's fast enough

Installiton

go get -u github.com/goraz/cast

Usage

This package has String, Int, Float, Duration, Bool and Uint functions than can cast different input type to specified type. Example:

castVal, _ := String(124) // "124"
castVal, _ := String(true) // "true"
castVal, _ := String(false) // "false"
castVal, _ := String(nil) // "false"

Also, there are equivalent MustString, MustInt, MustFloat, MustDuration, MustBool and MustUint functions which instead of returning error, make a panic error

Example:

castVal := MustString(124) // "124"
castVal := MustString(true) // "true"
castVal := MustString(false) // "false"
castVal := MustString(nil) // "false"

For more examples read tests

Contributing

If you are interested in contributing to this project please create a pull request. I appreciate your help!