Skip to content

Commit

Permalink
fix: fix default failover value (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
dskart committed Jun 14, 2023
1 parent 66bb15c commit d23fa41
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
5 changes: 1 addition & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func (a *Api) routeBase(w http.ResponseWriter, req *http.Request) {
return
}

sess.WithLogger(sess.Logger().With(zap.Int("statusCode", resp.StatusCode)))
if failover {
sess.WithLogger(sess.Logger().With(zap.Bool("failover", true)))
}
sess.WithLogger(sess.Logger().With(zap.Int("statusCode", resp.StatusCode)).With(zap.Bool("failover", failover)))

for k, values := range resp.Header {
for _, v := range values {
Expand Down
1 change: 1 addition & 0 deletions boltrouter/bolt_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func NewBoltRouter(ctx context.Context, logger *zap.Logger, cfg Config) (*BoltRo
Timeout: time.Duration(90) * time.Second,
}

logger.Debug("config", zap.Any("config", cfg))
br := &BoltRouter{
config: cfg,

Expand Down
8 changes: 8 additions & 0 deletions boltrouter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ type Config struct {
// Enable failover to a aws request if the Bolt request fails.
Failover bool `yaml:"Failover"`
}

func NewConfig() Config {
return Config{
Local: false,
Passthrough: false,
Failover: true,
}
}
6 changes: 6 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type Config struct {
BoltRouter boltrouter.Config `yaml:"BoltRouter"`
}

func NewConfig() Config {
return Config{
BoltRouter: boltrouter.NewConfig(),
}
}

const configPrefix = "SIDEKICK"

// UnmarshalConfigFromEnv populates config with values from environment variables. The names of the
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
}

var rootLogger *zap.Logger
var rootConfig Config
var rootConfig = NewConfig()

var rootCmd = &cobra.Command{
Use: "sidekick",
Expand Down
1 change: 0 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ func getBoltRouterConfig(cmd *cobra.Command) boltrouter.Config {
if cmd.Flags().Lookup("failover").Changed {
boltRouterConfig.Failover, _ = cmd.Flags().GetBool("failover")
}

return boltRouterConfig
}
2 changes: 1 addition & 1 deletion cmd/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestServeCmdConfig(t *testing.T) {
cfg := getBoltRouterConfig(testServeCmd)
assert.Equal(t, false, cfg.Local)
assert.Equal(t, false, cfg.Passthrough)
assert.Equal(t, false, cfg.Failover)
assert.Equal(t, true, cfg.Failover)
})

t.Run("EnvOnly", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.0
go.uber.org/zap v1.24.0
golang.org/x/sys v0.6.0
golang.org/x/term v0.1.0
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.4.3
Expand Down Expand Up @@ -47,6 +46,7 @@ require (
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down

0 comments on commit d23fa41

Please sign in to comment.