Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Last active September 13, 2018 01:37
Show Gist options
  • Save jeffotoni/85beb1d28198bf4c9f2982ac2526ff84 to your computer and use it in GitHub Desktop.
Save jeffotoni/85beb1d28198bf4c9f2982ac2526ff84 to your computer and use it in GitHub Desktop.
type DriverPg struct {
conn string
}
var instance *DriverPg
func Connect() *DriverPg {
instance = &DriverPg{conn: "DriverConnectPostgres"}
return instance
}
func init() {
Connect()
}
func main() {
// chamada
go func() {
time.Sleep(time.Millisecond * 600)
fmt.Println(instance.conn)
}()
go func() {
fmt.Println(*Connect())
}()
// 100 goroutine
for i := 0; i < 100; i++ {
go func(ix int) {
time.Sleep(time.Millisecond * 60)
fmt.Println(ix, " = ", instance.conn)
}(i)
}
fmt.Scanln()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment