Skip to content

Commit

Permalink
go v1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
wasilak committed Aug 9, 2023
1 parent 4c7cf9c commit 7df211c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 124 deletions.
4 changes: 2 additions & 2 deletions cache/redisCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *RedisCache) Get(ctx context.Context, cacheKey string) (interface{}, boo
item, err := c.Cache.Get(ctx, cacheKey).Result()

if err != nil || len(item) == 0 {
slog.ErrorCtx(ctx, "Error", slog.Any("message", err))
slog.ErrorContext(ctx, "Error", slog.Any("message", err))
return item, false
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *RedisCache) GetItemTTL(ctx context.Context, cacheKey string) (time.Dura
item, err := c.Cache.TTL(ctx, cacheKey).Result()

if err != nil {
slog.ErrorCtx(ctx, "Error", slog.Any("message", err))
slog.ErrorContext(ctx, "Error", slog.Any("message", err))
return item, false
}

Expand Down
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de
)

require (
Expand All @@ -32,16 +31,13 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
Expand Down Expand Up @@ -77,7 +73,6 @@ require (
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/grpc v1.57.0 // indirect
Expand Down
109 changes: 4 additions & 105 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func HandleSecretKey(ctx context.Context) error {
return err
}
viper.Set("secret_key", key)
slog.InfoCtx(ctx, "WARNING: No secret key provided. Setting randomly generated", slog.String("key", key))
slog.InfoContext(ctx, "WARNING: No secret key provided. Setting randomly generated", slog.String("key", key))
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions libs/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func initElasticClient(ctx context.Context, url, user, pass string) error {

json.NewDecoder(resp.Body).Decode(&body)

slog.DebugCtx(ctx, "Request response", slog.Any("body", body))
slog.DebugContext(ctx, "Request response", slog.Any("body", body))

return nil
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func UpsertUser(ctx context.Context, username string, elasticsearchUser Elastics

json.NewDecoder(resp.Body).Decode(&body)

slog.DebugCtx(ctx, "Request response", slog.Any("body", body))
slog.DebugContext(ctx, "Request response", slog.Any("body", body))

return nil
}
16 changes: 8 additions & 8 deletions libs/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func MainRoute(c echo.Context) error {

if len(user) == 0 {
err := errors.New("Header not provided: " + headerName)
slog.ErrorCtx(ctx, err.Error())
slog.ErrorContext(ctx, err.Error())
spanHeader.RecordError(err)
spanHeader.SetStatus(codes.Error, err.Error())
response := ErrorResponse{
Expand All @@ -80,7 +80,7 @@ func MainRoute(c echo.Context) error {

if len(userGroups) == 0 {
errorMessage := "Header not provided: " + headerName
slog.ErrorCtx(ctx, errorMessage)
slog.ErrorContext(ctx, errorMessage)
}

ctx, spanCacheGet := tracer.Start(ctx, "cache get")
Expand All @@ -94,9 +94,9 @@ func MainRoute(c echo.Context) error {
encryptedPasswordBase64, exists := cache.CacheInstance.Get(ctx, cacheKey)

if exists {
slog.DebugCtx(ctx, "Cache hit", slog.String("cacheKey", cacheKey))
slog.DebugContext(ctx, "Cache hit", slog.String("cacheKey", cacheKey))
} else {
slog.DebugCtx(ctx, "Cache miss", slog.String("cacheKey", cacheKey))
slog.DebugContext(ctx, "Cache miss", slog.String("cacheKey", cacheKey))
}
spanCacheGet.End()

Expand All @@ -113,7 +113,7 @@ func MainRoute(c echo.Context) error {
spanCacheMiss.AddEvent("Generating temporary user password")
password, err := GenerateTemporaryUserPassword(ctx)
if err != nil {
slog.ErrorCtx(ctx, "Error", slog.Any("message", err))
slog.ErrorContext(ctx, "Error", slog.Any("message", err))
return c.JSON(http.StatusInternalServerError, err)
}

Expand Down Expand Up @@ -142,14 +142,14 @@ func MainRoute(c echo.Context) error {
viper.GetString("elasticsearch_password"),
)
if err != nil {
slog.ErrorCtx(ctx, "Error", slog.Any("message", err))
slog.ErrorContext(ctx, "Error", slog.Any("message", err))
return c.JSON(http.StatusInternalServerError, err)
}

spanCacheMiss.AddEvent("Upserting user in Elasticsearch")
err = UpsertUser(ctx, user, elasticsearchUser)
if err != nil {
slog.ErrorCtx(ctx, "Error", slog.Any("message", err))
slog.ErrorContext(ctx, "Error", slog.Any("message", err))
return c.JSON(http.StatusInternalServerError, err)
}
}
Expand All @@ -165,7 +165,7 @@ func MainRoute(c echo.Context) error {
itemCacheDuration, _ := cache.CacheInstance.GetItemTTL(ctx, cacheKey)

if viper.GetBool("extend_cache") && itemCacheDuration > 0 && itemCacheDuration < cache.CacheInstance.GetTTL(ctx) {
slog.DebugCtx(ctx, fmt.Sprintf("User %s: extending cache TTL (from %s to %s)", user, itemCacheDuration, viper.GetString("cache_expire")))
slog.DebugContext(ctx, fmt.Sprintf("User %s: extending cache TTL (from %s to %s)", user, itemCacheDuration, viper.GetString("cache_expire")))
cache.CacheInstance.ExtendTTL(ctx, cacheKey, encryptedPasswordBase64)
}
spanItemCache.End()
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
panic(err)
}

slog.DebugCtx(ctx, "logger", slog.Any("setings", viper.AllSettings()))
slog.DebugContext(ctx, "logger", slog.Any("setings", viper.AllSettings()))

cache.CacheInit(ctx)

Expand Down

0 comments on commit 7df211c

Please sign in to comment.