Skip to content

Commit

Permalink
fix backwards compatibility (#63)
Browse files Browse the repository at this point in the history
backwards compatibility
  • Loading branch information
lkingland authored Mar 14, 2024
1 parent 6e2da55 commit 8c65371
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
15 changes: 2 additions & 13 deletions http/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package http

import (
"context"
"fmt"
"net/http"

"github.com/rs/zerolog/log"
)

// Handler is a function instance which can handle a request.
Expand Down Expand Up @@ -49,19 +46,11 @@ type LivenessReporter interface {
type DefaultHandler struct {
// TODO: Update type HandleFunc when backwards compatibility no
// longer needed:
Handler any
Handler handleFuncDeprecated
}

func (f DefaultHandler) Handle(w http.ResponseWriter, r *http.Request) {
if i, ok := f.Handler.(HandleFunc); ok {
i(w, r)
} else if i, ok := f.Handler.(handleFuncDeprecated); ok {
i(r.Context(), w, r)
} else {
msg := "function does not implement Handle. Skipping invocation."
log.Debug().Msg(msg)
fmt.Fprintln(w, msg)
}
f.Handler(r.Context(), w, r)
}

type handleFuncDeprecated func(context.Context, http.ResponseWriter, *http.Request)
8 changes: 0 additions & 8 deletions http/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ func logImplements(f any) {
if _, ok := f.(LivenessReporter); ok {
log.Info().Msg("Function implements Alive")
}

// Warn if using the deprecated static handler:
if i, ok := f.(DefaultHandler); ok {
log.Info().Msg("Function implements Handle")
if _, ok = i.Handler.(handleFuncDeprecated); ok {
log.Warn().Msg("The Handle method signature used has been deprecated. Please remove the context object argument. Future versions will remove support for this signature.")
}
}
}

// Start
Expand Down

0 comments on commit 8c65371

Please sign in to comment.