Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: net: add MarshalText/UnmarshalText to IPMask #40436

Open
ChrisSwanson opened this issue Jul 27, 2020 · 0 comments
Open

proposal: net: add MarshalText/UnmarshalText to IPMask #40436

ChrisSwanson opened this issue Jul 27, 2020 · 0 comments
Labels
Milestone

Comments

@ChrisSwanson
Copy link

What version of Go are you using (go version)?

$ go version
1.14.6

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cswanson/Library/Caches/go-build"
GOENV="/Users/cswanson/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/cswanson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/cswanson/go/src/github.com/golang/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wb/vtqrcvns4h7ghfrl_m75_z7c0000gn/T/go-build009589323=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm trying to json marshal and unmarshal net.IPNet objects, but the net.IPMask object currently does not support marshalling to text formats in a human readable/parsable format. When a net.IPMask object is attempted to be json marshalled, it is currently being transformed from a byte slice to a base64 string (as per the encode/json standards).

Here's an example:
https://play.golang.org/p/EGjSJeVQ9W-

Right now I am working around this, through type aliasing and methods, but it would be nice if this were either in its hex format, that it is displayed as in when using the String method to keep with backwards compatibility.
This seems to be a somewhat known issue to some regard as it is mentioned within a previous issue, although not yet followed up upon from what I was able to see: #29678 (comment)
Ideally in a future update, it would be great if the IPMask String method and potentially this text marshal were in a more well known format such as dot-decimal notation, for IPv4 instead of encoded to hex, as it is currently displayed, but that sounds like another issue aside from the json marshaling issue I am currently filing for.

What did you expect to see?

I expect net.IPMask to be marshaled to a text format, and consistent with net.IP and enable net.IPNet to be json marshaled leaving all objects in a human readable/parsable format.

What did you see instead?

A json marshaled version of these items in a non human readable fashion (base64 encoded translation of the byte slice).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

2 participants