Skip to content

Instantly share code, notes, and snippets.

@pulkitkumar
Last active August 10, 2018 12:50
Show Gist options
  • Save pulkitkumar/31c105171649331d2d8016c51c519828 to your computer and use it in GitHub Desktop.
Save pulkitkumar/31c105171649331d2d8016c51c519828 to your computer and use it in GitHub Desktop.
GoLang Value Sharing
package main
import (
"net/http"
"github.com/pkg/errors"
)
type User struct {
Name string
Email string
}
func Fetch(u *User) error {
resp, err := http.Get("url")
if err != nil {
return errors.Wrap(err, "network read error")
}
u.Name = "Abc" // read from resp
u.Email = "[email protected]" // read from resp
return nil
}
func main() {
var u User
err := Fetch(&u)
if err != nil {
// handle err here
}
modifyEmail(&u)
}
func modifyEmail(u *User) {
u.Email = "new Email"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment