08e5e4d956
In Go you can format numbers in different ways, as doucment in https://go.dev/ref/spec#Integer_literals. ParseInt with a base of 0 will infer the correct base for the number based on a prefix 0x, 0b etc, and also supports the use of the _ to separate digits. This can be helpful with long numbers, to make things easier to read. This switches the ParseInt() calls to use a base of 0, ensuring that if ParseValue is called with an int like 100_000 it'll parse correctly instead of throw an error. |
||
---|---|---|
.github/workflows | ||
.gitignore | ||
LICENSE | ||
README.md | ||
go.mod | ||
go.sum | ||
scalar.go | ||
scalar_test.go |
README.md
Scalar parsing library
Scalar is a library for parsing strings into arbitrary scalars (integers, floats, strings, booleans, etc). It is helpful for tasks such as parsing strings passed as environment variables or command line arguments.
go get github.com/alexflint/go-scalar
The main API works as follows:
var value int
err := scalar.Parse(&value, "123")
There is also a variant that takes a reflect.Value
:
var value int
err := scalar.ParseValue(reflect.ValueOf(&value), "123")