Skip to content

Commit

Permalink
replace if with switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice committed Jul 30, 2024
1 parent b271b84 commit 0fb55f9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions slog/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ func DefaultConverter(addSource bool, replaceAttr func(groups []string, a slog.A
func attrToSentryEvent(attr slog.Attr, event *sentry.Event) {

Check failure on line 52 in slog/converter.go

View workflow job for this annotation

GitHub Actions / Lint

cyclomatic complexity 32 of func `attrToSentryEvent` is high (> 30) (gocyclo)
k := attr.Key
v := attr.Value
kind := attr.Value.Kind()
kind := v.Kind()

if k == "dist" && kind == slog.KindString {
switch {
case k == "dist" && kind == slog.KindString:
event.Dist = v.String()
} else if k == "environment" && kind == slog.KindString {
case k == "environment" && kind == slog.KindString:
event.Environment = v.String()
} else if k == "event_id" && kind == slog.KindString {
case k == "event_id" && kind == slog.KindString:
event.EventID = sentry.EventID(v.String())
} else if k == "platform" && kind == slog.KindString {
case k == "platform" && kind == slog.KindString:
event.Platform = v.String()
} else if k == "release" && kind == slog.KindString {
case k == "release" && kind == slog.KindString:
event.Release = v.String()
} else if k == "server_name" && kind == slog.KindString {
case k == "server_name" && kind == slog.KindString:
event.ServerName = v.String()
} else if attr.Key == "tags" && kind == slog.KindGroup {
case k == "tags" && kind == slog.KindGroup:
event.Tags = attrsToString(v.Group()...)
} else if attr.Key == "transaction" && kind == slog.KindString {
// The implementation used slog.KindGroup instead of slog.KindString
case k == "transaction" && kind == slog.KindString:
event.Transaction = v.String()
} else if attr.Key == "user" && kind == slog.KindGroup {
case k == "user" && kind == slog.KindGroup:
data := attrsToString(v.Group()...)
if id, ok := data["id"]; ok {
event.User.ID = id
Expand All @@ -97,12 +97,11 @@ func attrToSentryEvent(attr slog.Attr, event *sentry.Event) {
event.User.Segment = segment
delete(data, "segment")
}

Check warning on line 99 in slog/converter.go

View check run for this annotation

Codecov / codecov/patch

slog/converter.go#L97-L99

Added lines #L97 - L99 were not covered by tests

event.User.Data = data
} else if attr.Key == "request" && kind == slog.KindAny {
if req, ok := attr.Value.Any().(http.Request); ok {
case k == "request" && kind == slog.KindAny:
if req, ok := v.Any().(http.Request); ok {
event.Request = sentry.NewRequest(&req)

Check warning on line 103 in slog/converter.go

View check run for this annotation

Codecov / codecov/patch

slog/converter.go#L103

Added line #L103 was not covered by tests
} else if req, ok := attr.Value.Any().(*http.Request); ok {
} else if req, ok := v.Any().(*http.Request); ok {
event.Request = sentry.NewRequest(req)
} else {
if tm, ok := v.Any().(encoding.TextMarshaler); ok {
Expand All @@ -114,9 +113,10 @@ func attrToSentryEvent(attr slog.Attr, event *sentry.Event) {
}

Check warning on line 113 in slog/converter.go

View check run for this annotation

Codecov / codecov/patch

slog/converter.go#L107-L113

Added lines #L107 - L113 were not covered by tests
}
}
} else if kind == slog.KindGroup {
event.Extra[attr.Key] = attrsToMap(attr.Value.Group()...)
} else {
event.Extra[attr.Key] = attr.Value.Any()
case kind == slog.KindGroup:
event.Extra[k] = attrsToMap(v.Group()...)
default:
event.Extra[k] = v.Any()

Check warning on line 119 in slog/converter.go

View check run for this annotation

Codecov / codecov/patch

slog/converter.go#L118-L119

Added lines #L118 - L119 were not covered by tests
}

}

0 comments on commit 0fb55f9

Please sign in to comment.