Last active
August 10, 2018 12:50
-
-
Save pulkitkumar/31c105171649331d2d8016c51c519828 to your computer and use it in GitHub Desktop.
GoLang Value Sharing
This file contains hidden or 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 ( | |
"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