2

Usually I saw config file in many examples out there are in .env or .json file.

What if I decide to use .go file instead , is it uncommon, how it should be done?

I was thinking since .env file is static, if I want to put config like this

var currentDate = time.Now()
var currentDateFormat = currentDate.Format("2006-01-02")
var logPath = dir + "/log/" + currentDateFormat + ".log"

It can't be done in .env file so should I just keep the above config within function somewhere and stick with .env file?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Ardeus
  • 1,921
  • 3
  • 17
  • 26

1 Answers1

1

What if I decide to use .go file instead

Then it is no longer a config file (static content), but a source file, which needs to be compiled and part of your exe (runtime content).

It then could be part of an init() function for instance.
Or part of a config package source, in charge of loading your config as well as initializing the variables in your question.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • so is it not recommended? stick with static file? – Ardeus Mar 12 '19 at 07:22
  • @Ardeus Both have their role: static file for static data, source code for dynamic runtime values (like `time.Now()`... which can makes sense only at runtime) – VonC Mar 12 '19 at 07:44