mirror of
https://github.com/nxshock/go-uno.git
synced 2026-12-03 14:49:32 +05:00
UNO support for the Go language
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| testdata | ||
| .gitignore | ||
| consts.go | ||
| decoder.go | ||
| encoder.go | ||
| error.go | ||
| go.mod | ||
| go.sum | ||
| logic.go | ||
| pairedvalue.go | ||
| pairedvalue_test.go | ||
| README.md | ||
| record.go | ||
| scanner.go | ||
| sortkeys.go | ||
| tags.go | ||
| uno.go | ||
| uno_test.go | ||
| values.go | ||
UNO support for the Go language
UNO stands from UNderstandable UNiversal NOtation of Objects. This Go package provides a reflection interface similar to
Go's standard library json package.
This package currenlty targets UNO Core Specification.
Caution
Early alpha stage, use with caution.
Installation
go get github.com/nxshock/go-uno
Usage
Simple marshal/unmarshal
Marshal:
s := struct {
A int
B string
}{
A: 123,
B: "456"}
bytes, err := uno.Marshal(s)
fmt.Println(string(bytes)) // "A= 123\nB: 456\n"
Unmarshal:
bytes := []byte("A= 123\nB: 456\n")
s := struct {
A int
B string
}{}
err := uno.Unmarshal(bytes, &s) // err is uno.DecodeError struct with additional info like error line or expected/got values
fmt.Printf("%+v", s) // {A:123 B:456}
Raw unmarshal
bytes := []byte("A= 123\nB:\n\tB1: 456\n\tB2: 789")
var s map[string]any
err := uno.Unmarshal(bytes, &s)
fmt.Printf("%+v", s) // map[A:123 B:map[B1:456 B2:789]]