Skip to content

Commit

Permalink
refactor(env): better env names
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent 14281e7 commit 4ca1d9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
SERVICE_NAME=spoty
PROD=false
CLIENT_ID=111fedce236f4d34a607711a7ac4a606
CLIENT_SECRET=fb4d98819b912dfd90d5803bb668ad24
HOST=localhost
PORT=13337
SPOTIFY_CLIENT_ID=111fedce236f4d34a607711a7ac4a606
SPOTIFY_CLIENT_SECRET=fb4d98819b912dfd90d5803bb668ad24
HTTP_SERVER_HOST=localhost
HTTP_SERVER_PORT=13337
CACHE_MAX_KEYS=64
CACHE_MAX_COST=1000000
JAEGER_ENDPOINT=http://localhost:14268/api/traces
SERVICE_NAME=spoty
JAEGER_ENDPOINT=http://localhost:14268/api/traces
18 changes: 9 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ var Module = fx.Options(

// Config is the configuration for the application.
type Config struct {
Prod bool `envconfig:"PROD" default:"false"`
ClientID string `envconfig:"CLIENT_ID" required:"true"`
ClientSecret string `envconfig:"CLIENT_SECRET" required:"true"`
Host string `envconfig:"HOST" default:"localhost"`
Port int `envconfig:"PORT" default:"13337"`
CacheMaxKeys int64 `envconfig:"CACHE_MAX_KEYS" default:"64"`
CacheMaxCost int64 `envconfig:"CACHE_MAX_COST" default:"1000000"`
JaegerEndpoint string `envconfig:"JAEGER_ENDPOINT" default:"http://localhost:14268/api/traces"`
ServiceName string `envconfig:"SERVICE_NAME" default:"spoty"`
ServiceName string `envconfig:"SERVICE_NAME" default:"spoty"`
Prod bool `envconfig:"PROD" default:"false"`
SpotifyClientID string `envconfig:"SPOTIFY_CLIENT_ID" required:"true"`
SpotifyClientSecret string `envconfig:"SPOTIFY_CLIENT_SECRET" required:"true"`
HttpServerHost string `envconfig:"HTTP_SERVER_HOST" default:"localhost"`
HttpServerPort int `envconfig:"HTTP_SERVER_PORT" default:"13337"`
CacheMaxKeys int64 `envconfig:"CACHE_MAX_KEYS" default:"64"`
CacheMaxCost int64 `envconfig:"CACHE_MAX_COST" default:"1000000"`
JaegerEndpoint string `envconfig:"JAEGER_ENDPOINT" default:"http://localhost:14268/api/traces"`
}

// New processes and returns a new application Config.
Expand Down
2 changes: 1 addition & 1 deletion http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewServer(

s := Server{
router: gin.Default(),
addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
addr: fmt.Sprintf("%s:%d", cfg.HttpServerHost, cfg.HttpServerPort),
logger: logger,
tracer: tracer,
spoty: spoty,
Expand Down
6 changes: 3 additions & 3 deletions spoty/spoty.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ func New(
cache *cache.Cache,
health *health.Checks,
) (*Spoty, error) {
if cfg.ClientID == "" || cfg.ClientSecret == "" {
if cfg.SpotifyClientID == "" || cfg.SpotifyClientSecret == "" {
return nil, errors.New("missing clientID or clientSecret")
}

auth := spotify.NewAuthenticator(
fmt.Sprintf("http://%s:%d/api/callback", cfg.Host, cfg.Port),
fmt.Sprintf("http://%s:%d/api/callback", cfg.HttpServerHost, cfg.HttpServerPort),
spotify.ScopeUserReadCurrentlyPlaying,
spotify.ScopeUserReadPlaybackState,
)

auth.SetAuthInfo(cfg.ClientID, cfg.ClientSecret)
auth.SetAuthInfo(cfg.SpotifyClientID, cfg.SpotifyClientSecret)

state, err := uuid.NewRandom()
if err != nil {
Expand Down

0 comments on commit 4ca1d9c

Please sign in to comment.