// u is type *url.URL
u, err := url.Parse("http://username:password@bing.com/search?q=dotnet")
if err != nil {
log.Fatal(err)
}
// u.User is type *url.Userinfo, it is parsed from "username:password"
fmt.Printf("%T, %v\n",u.User, *u.User)
// u.User is empty, we lost it
user,_ := json.Marshal(u)
fmt.Println(string(user))
I believe the reason it’s not encoding the user values is simply because the url.UserInfo’s username and password fields are unexported so therefore won’t get marshalled since the encoders only encode exported fields.
Edit: You can do something like this if you want to have the url.Userinfo encoded alongside the url.URL values. There’s probably a better way, but this is just off of the top of my head.