Skip to content

Commit

Permalink
chore: tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm committed Mar 27, 2024
1 parent c542983 commit ecc0a23
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions domain/apiresponses/failure_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func (f *FailureResponse) ErrorResponse() interface{} {
}
}

// ValidatedStatusCode returns the HTTP response status code. If the code is not 4xx
// or 5xx, an InternalServerError will be returned instead.
func (f *FailureResponse) ValidatedStatusCode(logger *slog.Logger) int {
if f.statusCode < 400 || 600 <= f.statusCode {
if logger != nil {
Expand Down
3 changes: 1 addition & 2 deletions handlers/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"log/slog"
"net/http"

"github.com/pivotal-cf/brokerapi/v10/internal/blog"

"github.com/pivotal-cf/brokerapi/v10/domain"
"github.com/pivotal-cf/brokerapi/v10/internal/blog"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions handlers/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"log/slog"
"net/http"

"github.com/pivotal-cf/brokerapi/v10/internal/blog"

"github.com/go-chi/chi/v5"
"github.com/pivotal-cf/brokerapi/v10/domain"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"
"github.com/pivotal-cf/brokerapi/v10/internal/blog"
"github.com/pivotal-cf/brokerapi/v10/middlewares"
)

Expand Down
3 changes: 1 addition & 2 deletions handlers/deprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"log/slog"
"net/http"

"github.com/pivotal-cf/brokerapi/v10/internal/blog"

"github.com/go-chi/chi/v5"
"github.com/pivotal-cf/brokerapi/v10/domain"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"
"github.com/pivotal-cf/brokerapi/v10/internal/blog"
"github.com/pivotal-cf/brokerapi/v10/middlewares"
)

Expand Down
3 changes: 1 addition & 2 deletions handlers/get_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"log/slog"
"net/http"

"github.com/pivotal-cf/brokerapi/v10/internal/blog"

"github.com/go-chi/chi/v5"
"github.com/pivotal-cf/brokerapi/v10/domain"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"
"github.com/pivotal-cf/brokerapi/v10/internal/blog"
"github.com/pivotal-cf/brokerapi/v10/middlewares"
)

Expand Down
12 changes: 7 additions & 5 deletions internal/blog/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// idiosyncrasies of lager, minimizes boilerplate code, and keeps the behavior as similar as possible.
// It also implements the slog.Handler interface so that it can easily be converted into a slog.Logger.
// This is useful when calling public APIs (such as FailureResponse.ValidatedStatusCode) which take a
// slog.Logger as an input, and because they are public cannot take a Blog as in input.
// slog.Logger as an input, and because they are public cannot take a Blog as an input.
package blog

import (
Expand Down Expand Up @@ -81,16 +81,18 @@ func (b Blog) WithGroup(string) slog.Handler {
return b
}

// Handle is required implement the slog.Handler interface
func (b Blog) Handle(_ context.Context, record slog.Record) error {
msg := join(b.prefix, record.Message)
switch record.Level {
case slog.LevelDebug:
b.logger.Debug(join(b.prefix, record.Message))
b.logger.Debug(msg)
case slog.LevelInfo:
b.logger.Info(join(b.prefix, record.Message))
b.logger.Info(msg)
case slog.LevelWarn:
b.logger.Warn(join(b.prefix, record.Message))
b.logger.Warn(msg)
default:
b.logger.Error(join(b.prefix, record.Message))
b.logger.Error(msg)
}

return nil
Expand Down

0 comments on commit ecc0a23

Please sign in to comment.