Skip to content

Commit

Permalink
Implement singleton pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrts committed Feb 20, 2016
1 parent a8f8670 commit b0918f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions singleton/singleton.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b0918f7

Please sign in to comment.