Skip to content

Commit

Permalink
feat: Environment not directly configurable but read from APP_ENV
Browse files Browse the repository at this point in the history
We use mitchellh/mapstructure to parse the values from the configuration
into the Config struct. Any private field is ignored by mapstructure; in
this way it can be read directly from the ENV.
  • Loading branch information
Edoardo Rossi committed Jul 2, 2020
1 parent e85d10a commit f0e6b99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/tracking/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package tracking

import (
"fmt"
"os"

cbuilder "git.lo/microservices/sdk/go-sdk/internal/pkg/configuration/builder"
)

// Config stores the configuration for the tracking.
type Config struct {
Environment string `mapstructure:"environment"`
environment string
Release string `mapstructure:"release"`
SentryDSN string `mapstructure:"dsn"`
ServerName string `mapstructure:"servername"`
Expand All @@ -17,6 +18,7 @@ type Config struct {
// NewConfig returns a new TrackingConfig instance
func NewConfig() (*Config, error) {
config := &Config{}
config.environment = os.Getenv("APP_ENV")

viperBuilder := cbuilder.New("sentry")

Expand Down
2 changes: 1 addition & 1 deletion pkg/tracking/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewSentryHook(config *Config) (*Hook, error) {
// The release to be sent with events.
Release: config.Release,
// The environment to be sent with events.
Environment: config.Environment,
Environment: config.environment,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit f0e6b99

Please sign in to comment.