Methods; specifically pointer receivers. Using a value will create copies
of the struct on every method call whereas pointers will use the same
struct.
Another benefit is to optionally do an atomic swap or use a mutex guard if
you wanted to change the instance at runtime (eg config reloads).
Pers
does the singleton variable for any reason need to be a pointer ?
On Thursday, June 30, 2016 at 4:07:08 PM UTC-7, Nathan Fisher wrote:
>
> I often put all of my wire-up in main which ensures that it's only one
> instance. Then I create a struct that all of the dependencies hang off of
> like log
I often put all of my wire-up in main which ensures that it's only one
instance. Then I create a struct that all of the dependencies hang off of
like loggers and clients.
On Thu, 30 Jun 2016 at 23:30, Val wrote:
> Indeed.
> I find it weird that the authors care more about lazy init (not strictly
Indeed.
I find it weird that the authors care more about lazy init (not strictly
required for singletons) than about ensuring properly that multiple
instanciation cannot happen.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe fro
On Thu, Jun 30, 2016, at 01:10 PM, awickert wrote:
>
>
> Am Donnerstag, 30. Juni 2016 08:29:32 UTC+2 schrieb krma...@gmail.com:
>> I want a single instance of a client handle to be initialized.
>>
>> Is it ok to declare the instance as
>>
>> var client MetricsClient
>>
>> and then initialize
On Thu, Jun 30, 2016, at 01:10 PM, awickert wrote:
>
>
> Am Donnerstag, 30. Juni 2016 08:29:32 UTC+2 schrieb krma...@gmail.com:
>> I want a single instance of a client handle to be initialized.
>>
>> Is it ok to declare the instance as
>>
>> var client MetricsClient
>>
>> and then initialize
If you really need this, Svett Ralchev provides a nice example using
sync.Once() in his blog:
http://blog.ralch.com/tutorial/design-patterns/golang-singleton/
On Thursday, June 30, 2016 at 8:29:32 AM UTC+2, krma...@gmail.com wrote:
> I want a single instance of a client handle to be initialized.
Am Donnerstag, 30. Juni 2016 08:29:32 UTC+2 schrieb krma...@gmail.com:
>
> I want a single instance of a client handle to be initialized.
>
> Is it ok to declare the instance as
>
> var client MetricsClient
>
> and then initialize it using sync.Once().
>
> Is it required for some reason that the