What is wrong with calling it second time?

I have two calls to config.GetConfig() and IDE shows me an error on the second call

func main() {
	config := config.GetConfig()
	config.Port = 999
	fmt.Println(config.Port) // 999

	config1 := config.GetConfig() // config.GetConfig undefined (type config.Config has no field or method GetConfig)

where in config package

var cfg Config
func init(){
	cfg = Config{
		Host:        _host,

func GetConfig() Config {
	return cfg

What it the problem here?

1 Like

sorry, I’ve found the problem - it was the same name for packege and for local variable


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.