-1

I am following the solution (accepted answer) given here as to load configuration values in Go. So far so good.

However, I want to use standard configuration load functions across different modules of the application and for simplicity and ease of it I am trying to achieve loading configurations without explicitly defining a customer object such as type Configuration struct.

Because each configuration file would be different and I don't want to define multiple structs and structs everywhere and then change them when a new value is added/deleted in the configurations.

I might be unfair to compare but I am looking for which in python would be just like this:

//in config.py
ENVIRONMENT = 'PROD'

//in main.py
import config
...
if config.ENVIRONMENT == 'PROD':
...

Is there such a possibility?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Maven
  • 14,587
  • 42
  • 113
  • 174

1 Answers1

2

You can use a map[string]string type if all your config values are strings or a map[string]interface{} type if you need arbitrary value types.

Although map[string]interface{} is a bit more cumbersome and a bit less safe, because you can cast interface{} to any type.

Here is a guide for using map[string]interface{}: https://bitfieldconsulting.com/golang/map-string-interface