Documentation
¶
Index ¶
- func DuckParse[Raw encoded](raw Raw, opts ...Option) (any, error)
- func Format[T any](v T, opts ...Option) (string, error)
- func IsRegistered[T any](i ...T) bool
- func Parse[T any, Raw encoded](raw Raw, opts ...Option) (T, error)
- func ParseReflect[Raw encoded](typ reflect.Type, raw Raw, opts ...Option) (reflect.Value, error)
- func Register[T any](parser parseFunc[T], formatter formatFunc[T]) func()
- type Option
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format allows you to format a value into a string format
Example ¶
package main import ( "go.llib.dev/frameless/pkg/convkit" ) func main() { formatted, err := convkit.Format(42.24) _, _ = formatted, err // "42.24", nil }
func IsRegistered ¶
func Parse ¶
Example ¶
package main import ( "go.llib.dev/frameless/pkg/convkit" ) func main() { _, _ = convkit.Parse[string]("hello") _, _ = convkit.Parse[int]("42") _, _ = convkit.Parse[float64]("42.24") _, _ = convkit.Parse[[]string]("a,b,c", convkit.Options{Separator: ","}) _, _ = convkit.Parse[[]string]([]byte(`["a","b","c"]`), convkit.Options{Separator: ","}) }
func ParseReflect ¶
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func ParseWith ¶
Example ¶
package main import ( "fmt" "strings" "go.llib.dev/frameless/pkg/convkit" ) func main() { // export FOO=foo:baz type Conf struct { Foo string Bar string } parserFunc := func(v string) (Conf, error) { parts := strings.SplitN(v, ":", 1) if len(parts) != 2 { return Conf{}, fmt.Errorf("invalid format") } return Conf{ Foo: parts[0], Bar: parts[1], }, nil } conf, err := convkit.Parse[Conf]("foo:bar", convkit.ParseWith(parserFunc)) _, _ = conf, err }
type Options ¶
type Options struct { // Separator is the separator character which will be used to detect list elements. Separator string // TimeLayout is the time layout format which will be used to parse time values. TimeLayout string // ParseFunc is used to Parse the input data. It follows the signature of the json.Unmarshal function. ParseFunc func(data []byte, ptr any) error }
Click to show internal directories.
Click to hide internal directories.