Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created August 3, 2022 08:44
Show Gist options
  • Save podhmo/22eafdcbbce915a6482d5557981d846d to your computer and use it in GitHub Desktop.
Save podhmo/22eafdcbbce915a6482d5557981d846d to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"net"
"os"
"strings"
)
type S struct {
IP net.IP `json:"ip"`
}
func main() {
{
s := S{IP: net.IPv4(127, 0, 0, 1)}
json.NewEncoder(os.Stdout).Encode(s)
}
{
var s S
r := strings.NewReader(`{"ip": "127.0.0.1"}`)
json.NewDecoder(r).Decode(&s)
fmt.Printf("%+v\n", s)
}
}
@podhmo
Copy link
Author

podhmo commented Aug 3, 2022

{"ip":"127.0.0.1"}
{IP:127.0.0.1}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment