C
C
cybervito212014-11-23 19:51:40
go
cybervito21, 2014-11-23 19:51:40

How to make a singleton in Go?

You need to work with one config from several package.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
uvelichitel, 2014-11-24
@cybervito21

package initsomething
func init() {var something type = whatyouwant}

package main
import _ "initsomething"

golang.org/ref/spec#Program_initialization_and_exe...
https://golang.org/doc/effective_go.html#init

N
neolink, 2014-11-23
@neolink

like this:
or like this (make public methods to get values):

package config

func Host() string {
    return "";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question