Skip to content

Commit

Permalink
refactor: use new key for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed May 15, 2024
1 parent ff29bd5 commit 2288306
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rest/handler/tenanthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TenantHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// add tenant to context
if tenantId := r.Header.Get("Tenant-ID"); tenantId == "" {
if tenantId := r.Header.Get("Tenant-Id"); tenantId == "" {
ctx = context.WithValue(ctx, "tenant-id", "default")
ctx = metadata.AppendToOutgoingContext(ctx, "tenant-id", "default")
} else {
Expand Down
6 changes: 3 additions & 3 deletions rest/handler/tenanthandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func TestTenantHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req.Header.Set("Tenant-ID", "tenant-1")
req.Header.Set("Tenant-Id", "tenant-1")
handler := TenantHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// add tenant to context
if tenantId := r.Header.Get("Tenant-ID"); tenantId == "" {
if tenantId := r.Header.Get("Tenant-Id"); tenantId == "" {
ctx = context.WithValue(ctx, "tenant-id", "default")
ctx = metadata.AppendToOutgoingContext(ctx, "tenant-id", "default")
} else {
Expand All @@ -36,7 +36,7 @@ func TestTenantHandlerByDefault(t *testing.T) {
handler := TenantHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// add tenant to context
if tenantId := r.Header.Get("Tenant-ID"); tenantId == "" {
if tenantId := r.Header.Get("Tenant-Id"); tenantId == "" {
ctx = context.WithValue(ctx, "tenant-id", "default")
ctx = metadata.AppendToOutgoingContext(ctx, "tenant-id", "default")
} else {
Expand Down

0 comments on commit 2288306

Please sign in to comment.