Type conversions. By force if necessary.
Cram will do its best to convert any type given to it. You're unlikely ever to need this library. This is only useful when you're writing dynamic code and must go from an unknown to a known type.
package main
import (
"fmt"
"github.com/ETLHero/cram"
)
func main() {
var numbers []int
cram.Into(&numbers, "1,2,3,4,5")
fmt.Println(numbers) // => [1 2 3 4 5]
}
- Extensible! See below.
- Map (hashing) lookup for conversations. No slow switch cases.
- Gracefully handles pointers
- Uses reflect package rather than casting. For all the above features.
Don't like a conversion? Missing a conversion? Add it yourself. The Conversions
variable holds all the conversions just add, replace or remove what you want and call the Into
function like normal.
Some conversions might not be obvious, like []float
to bool
. I think you are best off looking at the tests to see how they convert.
- Convert from Bool
- Convert from Float
- Convert from Int
- Convert from String
- Convert from Bool Slice
- Convert from Float Slice
- Convert from Int Slice
- Convert from String Slice