Skip to content

Golang Singleton Pattern

April 13, 2014

The best way I could manage to implement the singleton pattern in Go was by utilizing package encapsulation. I couldn’t use a const because it only allows for compile-time constants and NOT runtime constants. The singleton can only be created from inside the package (lowercase struct), so packages with a singleton should be as small as possible to avoid mistakenly creating more than one.

Advertisements

From → Golang

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: