1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  | 
package example
import (
	"sync"
)
// the singleton struct/object
type singleton struct{}
var instance *singleton
var once sync.Once
func GetSingleInstance() *singleton {
	once.Do(func() {
		instance = &singleton{}
	})
	return instance
}
  |