diff --git a/alerts/client.go b/alerts/client.go index 213c9df7a0..3c69d3b463 100644 --- a/alerts/client.go +++ b/alerts/client.go @@ -7,6 +7,8 @@ import ( "github.com/kelseyhightower/envconfig" "github.com/tidepool-org/platform/client" + "github.com/tidepool-org/platform/log" + "github.com/tidepool-org/platform/log/null" "github.com/tidepool-org/platform/platform" ) @@ -29,12 +31,15 @@ func NewClient(cfg *ClientConfig) (*Client, error) { // Upsert updates cfg in the service if it exists, or creates it if it doesn't. func (c *Client) Upsert(ctx context.Context, cfg *Config) error { + ctx = log.NewContextWithLogger(ctx, null.NewLogger()) url := c.client.ConstructURL("v1", "alerts", cfg.UserID, cfg.FollowedUserID) return c.client.RequestData(ctx, http.MethodPost, url, nil, cfg, nil) } // Delete the alerts config. func (c *Client) Delete(ctx context.Context, cfg *Config) error { + // Ideally the base client wouldn't require a logger, or if it found a nil, would use a null logger itself. + ctx = log.NewContextWithLogger(ctx, null.NewLogger()) url := c.client.ConstructURL("v1", "alerts", cfg.UserID, cfg.FollowedUserID) return c.client.RequestData(ctx, http.MethodDelete, url, nil, nil, nil) } @@ -42,7 +47,7 @@ func (c *Client) Delete(ctx context.Context, cfg *Config) error { // ClientConfig leverages platform.Config for the alerts client. type ClientConfig struct { *platform.Config - Address string `envconfig:"TIDEPOOL_DATA_CLIENT_ADDRESS"` + Address string `envconfig:"TIDEPOOL_DATA_CLIENT_ADDRESS" required:"true"` } // ConfigLoader abstracts the method by which config values are loaded. diff --git a/log/context.go b/log/context.go index 5d1a550391..d1ea5e253a 100644 --- a/log/context.go +++ b/log/context.go @@ -16,7 +16,7 @@ func LoggerFromContext(ctx context.Context) Logger { return logger } } - return nil + return NewNullLogger() } func ContextWithField(ctx context.Context, key string, value interface{}) context.Context { diff --git a/log/null.go b/log/null.go new file mode 100644 index 0000000000..fa52ddcfb1 --- /dev/null +++ b/log/null.go @@ -0,0 +1,71 @@ +package log + +func NewNullLogger() *nullLogger { + return &nullLogger{} +} + +type nullLogger struct{} + +func (l *nullLogger) Log(level Level, message string) { + return +} + +func (l *nullLogger) Debug(message string) { + return +} + +func (l *nullLogger) Info(message string) { + return +} + +func (l *nullLogger) Warn(message string) { + return +} + +func (l *nullLogger) Error(message string) { + return +} + +func (l *nullLogger) Debugf(message string, args ...interface{}) { + return +} + +func (l *nullLogger) Infof(message string, args ...interface{}) { + return +} + +func (l *nullLogger) Warnf(message string, args ...interface{}) { + return +} + +func (l *nullLogger) Errorf(message string, args ...interface{}) { + return +} + +func (l *nullLogger) WithError(err error) Logger { + return l +} + +func (l *nullLogger) WithField(key string, value interface{}) Logger { + return l +} + +func (l *nullLogger) WithFields(fields Fields) Logger { + return l +} + +func (l *nullLogger) WithLevelRank(level Level, rank Rank) Logger { + return l +} + +func (l *nullLogger) WithLevelRanks(levelRanks LevelRanks) Logger { + return l +} + +func (l *nullLogger) WithLevel(level Level) Logger { + return l +} + +func (l *nullLogger) Level() Level { + return DebugLevel +} diff --git a/platform/config.go b/platform/config.go index e045dbc384..e8b114c110 100644 --- a/platform/config.go +++ b/platform/config.go @@ -10,7 +10,7 @@ import ( // Config extends client.Config with additional properties. type Config struct { *client.Config - ServiceSecret string `envconfig:"TIDEPOOL_SERVICE_SECRET"` + ServiceSecret string `envconfig:"TIDEPOOL_SERVER_SECRET" required:"true"` } func NewConfig() *Config {