+
Skip to content

goraz/cast

Repository files navigation

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!

About

A simple type cast for go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载