diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-07-20 15:22:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 15:22:49 -0700 |
commit | 58839cefb50e56ae5b157b37e9814ae83ceee70b (patch) | |
tree | 5de966481678096fc9567f74f96673b34a65127c /vendor/github.com/hashicorp/go-sockaddr/sockaddr.go | |
parent | e2f4492eadb5d3c58606b1fdd5774b63a07c236a (diff) | |
download | chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.gz chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.bz2 chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.zip |
Upgrading server dependancies (#6984)
Diffstat (limited to 'vendor/github.com/hashicorp/go-sockaddr/sockaddr.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-sockaddr/sockaddr.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-sockaddr/sockaddr.go b/vendor/github.com/hashicorp/go-sockaddr/sockaddr.go index 51389ebe9..826c91c2e 100644 --- a/vendor/github.com/hashicorp/go-sockaddr/sockaddr.go +++ b/vendor/github.com/hashicorp/go-sockaddr/sockaddr.go @@ -1,6 +1,7 @@ package sockaddr import ( + "encoding/json" "fmt" "strings" ) @@ -176,3 +177,30 @@ func sockAddrInit() { func SockAddrAttrs() []AttrName { return sockAddrAttrs } + +// Although this is pretty trivial to do in a program, having the logic here is +// useful all around. Note that this marshals into a *string* -- the underlying +// string representation of the sockaddr. If you then unmarshal into this type +// in Go, all will work as expected, but externally you can take what comes out +// and use the string value directly. +type SockAddrMarshaler struct { + SockAddr +} + +func (s *SockAddrMarshaler) MarshalJSON() ([]byte, error) { + return json.Marshal(s.SockAddr.String()) +} + +func (s *SockAddrMarshaler) UnmarshalJSON(in []byte) error { + var str string + err := json.Unmarshal(in, &str) + if err != nil { + return err + } + sa, err := NewSockAddr(str) + if err != nil { + return err + } + s.SockAddr = sa + return nil +} |