Skip to content

Commit

Permalink
frontend: Assume versioned interface lookup succeeds
Browse files Browse the repository at this point in the history
The API version middleware will catch an invalid API version and
complete the request before the final handler function executes,
so handler functions can safely get the versioned interface from
the request context.
  • Loading branch information
Matthew Barnes committed Apr 4, 2024
1 parent 59ca2ee commit 7f0f522
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (f *Frontend) ArmResourceListByResourceGroup(writer http.ResponseWriter, re
func (f *Frontend) ArmResourceRead(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()
logger := ctx.Value(ContextKeyLogger).(*slog.Logger)
versionedInterface, _ := ctx.Value(ContextKeyVersion).(api.Version)
versionedInterface := ctx.Value(ContextKeyVersion).(api.Version)
logger.Info(fmt.Sprintf("%s: ArmResourceRead", versionedInterface))

// URL path is already lowercased by middleware.
Expand All @@ -207,7 +207,7 @@ func (f *Frontend) ArmResourceRead(writer http.ResponseWriter, request *http.Req
func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()
logger := ctx.Value(ContextKeyLogger).(*slog.Logger)
versionedInterface, _ := ctx.Value(ContextKeyVersion).(api.Version)
versionedInterface := ctx.Value(ContextKeyVersion).(api.Version)

logger.Info(fmt.Sprintf("%s: ArmResourceCreateOrUpdate", versionedInterface))

Expand Down Expand Up @@ -252,7 +252,7 @@ func (f *Frontend) ArmResourcePatch(writer http.ResponseWriter, request *http.Re
func (f *Frontend) ArmResourceDelete(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()
logger := ctx.Value(ContextKeyLogger).(*slog.Logger)
versionedInterface, _ := ctx.Value(ContextKeyVersion).(api.Version)
versionedInterface := ctx.Value(ContextKeyVersion).(api.Version)
logger.Info(fmt.Sprintf("%s: ArmResourceDelete", versionedInterface))

// URL path is already lowercased by middleware.
Expand Down

0 comments on commit 7f0f522

Please sign in to comment.