https://github.com/fern4lvarez/gonverter
Easy, straightforward type conversion for Go.
https://github.com/fern4lvarez/gonverter
Last synced: 6 months ago
JSON representation
Easy, straightforward type conversion for Go.
- Host: GitHub
- URL: https://github.com/fern4lvarez/gonverter
- Owner: fern4lvarez
- License: mit
- Created: 2013-03-28T17:05:24.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-07T13:23:50.000Z (about 12 years ago)
- Last Synced: 2024-06-19T18:08:41.974Z (11 months ago)
- Language: Go
- Homepage: http://godoc.org/github.com/fern4lvarez/gonverter
- Size: 180 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gonverter [](https://travis-ci.org/fern4lvarez/gonverter) [Documentation online](http://godoc.org/github.com/fern4lvarez/gonverter)
=====
Easy, straightforward type conversion for Go.**gonverter** package provides a homogeneous conversion interface for
Go basic types, based on a type names initials pattern:
```
´int´ -> I
´string´ -> S
´bool´ -> B
...
```This pattern makes possible to achieve conversions easily:
```
´int´ to ´string´: ItoS
´bool´ to ´int´: BtoS
...
```**Disclaimer**: Go already provides simple native conversions. This package
does not aim to replace them, just to put all of them together, making easier
to the Go developer to find the right conversion way without digging in
multiple doc sources.**TODO**:
```
´int8´ -> I8
´int16´ -> I16
´int32´ -> I32
´int64´ -> I64´uint´ -> U
´uint8´ -> U8
´byte´ -> B // alias for uint8
´uint16´ -> U16
´uint32´ -> U32
´rune´ -> R // alias for int32
´uint64´ -> U64
´uintptr´ -> Uptr´float32´ -> F
´float64´ -> F64´complex64´ -> C
´complex128´ -> C128
```##Install
```
go get github.com/fern4lvarez/gonverter
```##Usage
```
// gonversions.gopackage main
import (
"fmt"
gnv "github.com/fern4lvarez/gonverter"
)func main() {
var i, n int
var s string
var b booli = gnv.StoI("38")
// 38n = i + 3
// 41s = gnv.ItoS(n)
if s == "41" {
b = gnv.StoB(s)
// truei = gnv.BtoI(b)
// 1res := n + i
// 42b = gnv.ItoB(res)
if b { // true
fmt.Printf("It's %s, the answer is %s.", gnv.BtoS(b), gnv.ItoS(res))
}
}
}```
```
$ go run gonversions.go
It's true, the answer is 42.
```##License
gonverter is MIT licensed, see [here](https://github.com/fern4lvarez/gonverter/blob/master/LICENSE)