diff --git a/singleton/singleton.go b/singleton/singleton.go new file mode 100644 index 0000000..d85a4a6 --- /dev/null +++ b/singleton/singleton.go @@ -0,0 +1,20 @@ +package singleton + +import ( + "sync" +) + +type Object struct { +} + +var once sync.Once +var instance *Object + +func GetInstance() *Object { + // Creates a singleton instance once. + once.Do(func() { + instance = &singleton{} + }) + + return instance +}