Go install. Execute custom action

89 views Asked by At

I have a CLI Go application. This application is reading some environment variables, and reading a custom config file. And I don't want this env-variable to be set manually or the config file to be created manually. It would be great if these actions would be made by go install command. However, I haven't found a way to execute some additional actions during go install. Is it possible and what are the best practices to do so?

1

There are 1 answers

3
icza On

go install can't set environment variables and can't create config files for you.

The best practice is to have sensible defaults "built" into the app. The app should provide some options to override the defaults, e.g. command line flags, environment variables and config files.

If overrides (config files) do not exist, the app may create default config files on startup, and the app may even notify the user with a warning message that configuration did not exist, so the default settings will be used, and the app just created one with the defaults which the user can change / modify.