Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Add env vars for dev mode and analytics write key
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentluce committed Aug 25, 2024
1 parent f9f033c commit d4c093b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kontrol-service/api/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const (
)

// NewAnalyticsWrapper creates a new AnalyticsWrapper
func NewAnalyticsWrapper(isDevMode bool) *AnalyticsWrapper {
func NewAnalyticsWrapper(isDevMode bool, writeKey string) *AnalyticsWrapper {
if !isDevMode {
// This is the Segment write key for the "kontrol-service" project. It is not
// a sensitive value, but it could be extracted to an env var in the future
// to separate dev and prod traffic if desired.
client := analytics.New("1TeZVRY3ta9VYaNknKTCCKBZtcBllE6U")
client := analytics.New(writeKey)
logrus.Info("Segment analytics client initialized")
return &AnalyticsWrapper{client: &client}
}
Expand Down
16 changes: 12 additions & 4 deletions kontrol-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ import (
)

func main() {
devMode := flag.Bool("dev-mode", false, "Allow to run the service in local mode.")
var devMode bool
devMode = *flag.Bool("dev-mode", false, "Allow to run the service in local mode.")
if !devMode {
devModeEnvVarStr := os.Getenv("DEV_MODE")
if devModeEnvVarStr == "true" {
devMode = true
}
}

flag.Parse()

if *devMode {
if devMode {
logrus.Warn("Running in dev mode. CORS fully open.")
logrus.SetLevel(logrus.DebugLevel)
}

startServer(*devMode)
startServer(devMode)
}

func startServer(isDevMode bool) {
Expand Down Expand Up @@ -62,7 +69,8 @@ func startServer(isDevMode bool) {

// Create a new Segment analytics client instance.
// analyticsClient is not initialized in dev mode so events are not reported to Segment
analyticsWrapper := api.NewAnalyticsWrapper(isDevMode)
analyticsWriteKeyEnvVarStr := os.Getenv("ANALYTICS_WRITE_KEY")
analyticsWrapper := api.NewAnalyticsWrapper(isDevMode, analyticsWriteKeyEnvVarStr)
defer analyticsWrapper.Close()

// create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code
Expand Down

0 comments on commit d4c093b

Please sign in to comment.