Skip to content

runtime/debug: allow JSON encoding of BuildInfo  #51026

@hyangah

Description

@hyangah

go1.18 added MarshalText and UnmarshalText methods for BuildInfo.
https://pkg.go.dev/runtime/debug@go1.18beta2#BuildInfo

This addition changed the behavior of this program.

package main

import (
	"encoding/json"
	"fmt"
	"runtime/debug"
)

func main() {
	info, _ := debug.ReadBuildInfo()
	b, _ := json.MarshalIndent(info, " ", " ")
	fmt.Printf("%s\n", b)
}

With go1.17

{
  "Path": "example",
  "Main": {
   "Path": "example",
   "Version": "(devel)",
   "Sum": "",
   "Replace": null
  },
  "Deps": null
 }

With go1.18

"go\tgo1.18beta2\npath\texample\nmod\texample\t(devel)\t\nbuild\t-compiler=gc\nbuild\t-gcflags=all=-N -l\nbuild\tCGO_ENABLED=1\nbuild\tCGO_CFLAGS=-O0 -g\nbuild\tCGO_CPPFLAGS=\nbuild\tCGO_CXXFLAGS=\nbuild\tCGO_LDFLAGS=\nbuild\tGOARCH=amd64\nbuild\tGOOS=darwin\nbuild\tGOAMD64=v1\n"

My proposal is either drop MarshalText/UnmarshalText (instead String/Parse, Encode/Decode?), or provide MarshalJSON/UnmarshalJSON so JSON encoding can encode in a form that tools written in other languages can access the info easily.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions