feat!: rework the public API to json/v2-style variadic options
Test / test (push) Successful in 1m49s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-22 18:42:18 +02:00
parent 7ee155d1e9
commit 2e61ad0ba9
18 changed files with 398 additions and 393 deletions
+9 -11
View File
@@ -70,12 +70,11 @@ func ExampleMarshal() {
// port = 9090
}
func ExampleDecoder() {
func ExampleNumbersAsLiterals() {
var tree map[string]any
err := interpres.NewDecoder().
DisallowUnknownFields().
UseNumber().
Decode([]byte("rate = 1_000\n"), &tree)
err := interpres.Unmarshal([]byte("rate = 1_000\n"), &tree,
interpres.RejectUnknownFields(true),
interpres.NumbersAsLiterals(true))
if err != nil {
log.Fatal(err)
}
@@ -83,16 +82,15 @@ func ExampleDecoder() {
// Output: 1_000 1_000
}
func ExampleEncoder() {
func ExampleInlineTables() {
type Config struct {
Title string `toml:"title"`
Extras map[string]string `toml:"extras,inline"`
}
out, err := interpres.NewEncoder().
Layout(interpres.LayoutKindDeclaration).
LiteralMultiline(80).
InlineTables(40).
Marshal(Config{Title: "demo", Extras: map[string]string{"b": "two", "a": "one"}})
out, err := interpres.Marshal(Config{Title: "demo", Extras: map[string]string{"b": "two", "a": "one"}},
interpres.Layout(interpres.LayoutKindDeclaration),
interpres.LiteralMultiline(80),
interpres.InlineTables(40))
if err != nil {
log.Fatal(err)
}