Skip to content

Commit

Permalink
feat: when the name is empty, WithGroup returns the receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Jul 10, 2024
1 parent fc62ebf commit ced8470
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 26 deletions.
28 changes: 2 additions & 26 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Lint

on:
push:
tags:
branches:
pull_request:

jobs:
Expand All @@ -17,31 +15,9 @@ jobs:
stable: false
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
working-directory: ./

# Optional: golangci-lint command line arguments.
args: --timeout 60s --max-same-issues 50

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# optionally use a specific version of Go rather than the latest one
go_version: '1.21'
args: --timeout 120s --max-same-issues 50

- name: Bearer
uses: bearer/bearer-action@v2
5 changes: 5 additions & 0 deletions failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (h *FailoverHandler) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *FailoverHandler) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

handers := lo.Map(h.handlers, func(h slog.Handler, _ int) slog.Handler {
return h.WithGroup(name)
})
Expand Down
5 changes: 5 additions & 0 deletions middleware_inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (h *InlineMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *InlineMiddleware) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return NewInlineMiddleware(
h.enabledFunc,
h.handleFunc,
Expand Down
5 changes: 5 additions & 0 deletions middleware_inline_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ func (h *EnabledInlineMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *EnabledInlineMiddleware) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return NewEnabledInlineMiddleware(h.enabledFunc)(h.next.WithGroup(name))
}
5 changes: 5 additions & 0 deletions middleware_inline_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ func (h *HandleInlineMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *HandleInlineMiddleware) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return NewHandleInlineMiddleware(h.handleFunc)(h.next.WithGroup(name))
}
5 changes: 5 additions & 0 deletions middleware_inline_with_attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ func (h *WithAttrsInlineMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *WithAttrsInlineMiddleware) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return NewWithAttrsInlineMiddleware(h.withAttrsFunc)(h.next.WithGroup(name))
}
5 changes: 5 additions & 0 deletions middleware_inline_with_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ func (h *WithGroupInlineMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *WithGroupInlineMiddleware) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return NewWithGroupInlineMiddleware(h.withGroupFunc)(h.withGroupFunc(name, h.next.WithGroup))
}
5 changes: 5 additions & 0 deletions multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (h *FanoutHandler) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *FanoutHandler) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

handers := lo.Map(h.handlers, func(h slog.Handler, _ int) slog.Handler {
return h.WithGroup(name)
})
Expand Down
5 changes: 5 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (h *PoolHandler) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *PoolHandler) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

handers := lo.Map(h.handlers, func(h slog.Handler, _ int) slog.Handler {
return h.WithGroup(name)
})
Expand Down
5 changes: 5 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (h *RoutableHandler) WithAttrs(attrs []slog.Attr) slog.Handler {

// Implements slog.Handler
func (h *RoutableHandler) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}

return &RoutableHandler{
matchers: h.matchers,
handler: h.handler.WithGroup(name),
Expand Down

0 comments on commit ced8470

Please sign in to comment.