From 6d0c7f24a5207bb66357db306d0a25711a1f1900 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Thu, 8 Feb 2024 14:14:32 +0100 Subject: [PATCH] make fmt --- encoding/formeta/marshal.go | 65 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/encoding/formeta/marshal.go b/encoding/formeta/marshal.go index a3bbb8cd..b19d6fcb 100644 --- a/encoding/formeta/marshal.go +++ b/encoding/formeta/marshal.go @@ -32,30 +32,26 @@ func marshal(w io.Writer, k string, v interface{}) error { _, err := io.WriteString(w, s) return err } - if _, err := io.WriteString(w, k+" { "); err != nil { return err } - for _, f := range structs.New(v).Fields() { if !f.IsExported() { continue } - - var key string - var tagv = strings.Split(f.Tag("json"), ",") - + var ( + key string + tagv = strings.Split(f.Tag("json"), ",") + ) if len(tagv) > 0 && tagv[0] != "" { key = tagv[0] } else { key = f.Name() } - if err := marshal(w, key, f.Value()); err != nil { return err } } - if _, err := io.WriteString(w, " } "); err != nil { return err } @@ -102,33 +98,32 @@ func marshal(w io.Writer, k string, v interface{}) error { // Marshal serializes a value as metafacture formeta. Mostly complete, might missing some edge cases. // Example formeta snippets: // -// person-1 { -// Name: Grimm, -// Vorname: Wilhelm, -// Vorname: Carl -// } -// person-2 { -// Name: Grimm, -// Vorname: Jacob, -// } -// person-3 { -// surname: 'Jung', -// forename: 'Carl', forename: 'Gustav', -// affiliation { -// institution: 'Basel University', -// country: 'Switzerland', -// }, -// } -// 978-3-525-20764-2 { -// title: Kinder- und Hausmärchen, -// authoredById: person-1, -// authoredById: person-2, -// readById: person-3, -// publicationYear: 1986, -// publisher: Vandenhoeck und Ruprecht\: Göttingen, -// isbn: 978-3-525-20764-2 -// } -// +// person-1 { +// Name: Grimm, +// Vorname: Wilhelm, +// Vorname: Carl +// } +// person-2 { +// Name: Grimm, +// Vorname: Jacob, +// } +// person-3 { +// surname: 'Jung', +// forename: 'Carl', forename: 'Gustav', +// affiliation { +// institution: 'Basel University', +// country: 'Switzerland', +// }, +// } +// 978-3-525-20764-2 { +// title: Kinder- und Hausmärchen, +// authoredById: person-1, +// authoredById: person-2, +// readById: person-3, +// publicationYear: 1986, +// publisher: Vandenhoeck und Ruprecht\: Göttingen, +// isbn: 978-3-525-20764-2 +// } func Marshal(v interface{}) ([]byte, error) { buf := new(bytes.Buffer) if err := marshal(buf, "", v); err != nil {