Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Feb 8, 2024
1 parent 04823d8 commit 6d0c7f2
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions encoding/formeta/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6d0c7f2

Please sign in to comment.