Created
June 22, 2018 19:43
-
-
Save gagliardetto/42498d31143ab07983484442fc4d784a to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"time" | |
"github.com/davecgh/go-spew/spew" | |
) | |
func main() { | |
users := []User{ | |
{Name: "Al"}, | |
{Name: "John"}, | |
{Name: "Jack"}, | |
} | |
for k, v := range users { | |
v.SetID(k) | |
go watcher(&v) | |
} | |
spew.Dump(users) | |
time.Sleep(time.Hour) | |
} | |
func watcher(user *User) { | |
for { | |
time.Sleep(time.Second) | |
fmt.Println(user.Name) | |
} | |
} | |
type User struct { | |
Name string | |
ID int | |
} | |
// | |
func (user *User) SetName(name string) { | |
user.Name = name | |
} | |
func (user *User) SetID(id int) { | |
user.ID = id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment