Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV/PROD microservice flag design #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/pull_request_template.md

This file was deleted.

26 changes: 26 additions & 0 deletions golang_language_guidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dev vs Prod Flags
At root of go microservice define an env.go file with an init() function

This init function looks for a single required variable "ENV" and then sets either prod or dev env vars accordingly

This makes it easy to switch between dev and prod, keep track of env var changes, and works with any dev flow

your init() function should handle 3 cases as follows
```
func init()
if os.Getenv("ENV) == "prod" {
// set environment variables via either secret manager or hard coded here
os.Setenv("some var", "some value)...
thirdparty.secretmanager.getVar("some secret var", "some secret value")

// All env vars should be accessible via os.getenv("var name")
} else if os.Getenv("ENV") == "dev" {
// same deal as above, except use dev values for staging databases etc
} else {
// enforce ENV is set and valid or else quit
panic("ENV must be set to prod or dev")
}
}
```

Then access them in your program via os.Getenv("your var...")