Skip to content

Instantly share code, notes, and snippets.

@gagliardetto
Created June 22, 2018 19:43
Show Gist options
  • Save gagliardetto/42498d31143ab07983484442fc4d784a to your computer and use it in GitHub Desktop.
Save gagliardetto/42498d31143ab07983484442fc4d784a to your computer and use it in GitHub Desktop.
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