Skip to content

ETLHero/cram

Repository files navigation

Cram

go.dev reference

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.

Example

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]
}

Features

  • 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.

Extending

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.

Conversions

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.

About

Type conversions. By force if necessary.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages