Skip to content

Commit

Permalink
wit/bindgen: add JSON tag to Record structs
Browse files Browse the repository at this point in the history
Merge pull request #265 from lxfontes/lxfontes/serialize-tags
  • Loading branch information
ydnar authored Dec 28, 2024
2 parents 670072d + 17ff28c commit db23ebb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions tests/generated/wasi/filesystem/v0.2.0/types/types.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions tests/generated/wasi/sockets/v0.2.0/network/network.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/generated/wasi/sockets/v0.2.0/udp/udp.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wit/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,13 @@ func (g *generator) recordRep(file *gen.File, dir wit.Direction, r *wit.Record,
exported := len(goName) == 0 || token.IsExported(goName)
var b strings.Builder
b.WriteString("struct {\n")
stringio.Write(&b, "_ ", file.Import(g.opts.cmPackage), ".HostLayout")
stringio.Write(&b, "_ ", file.Import(g.opts.cmPackage), ".HostLayout `json:\"-\"`")
for i, f := range r.Fields {
if i == 0 || i > 0 && f.Docs.Contents != "" {
b.WriteRune('\n')
}
b.WriteString(formatDocComments(f.Docs.Contents, false))
stringio.Write(&b, fieldName(f.Name, exported), " ", g.typeRep(file, dir, f.Type), "\n")
stringio.Write(&b, fieldName(f.Name, exported), " ", g.typeRep(file, dir, f.Type), " `json:\"", f.Name, "\"`\n")
}
b.WriteRune('}')
return b.String()
Expand Down

0 comments on commit db23ebb

Please sign in to comment.