Created
August 3, 2022 08:44
-
-
Save podhmo/22eafdcbbce915a6482d5557981d846d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Author
podhmo
commented
Aug 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment