Golang Singleton
package example
import (
"fmt"
"sync"
)
var m *singleton
var once sync.Once
func GetInstance() *singleton {
once.Do(func() {
m = &singleton{}
})
return m
}
type singleton struct{}
func (p singleton) DoWork() {
fmt.Println("Do Work")
}