fix: module id and linting issues
This commit is contained in:
@@ -7,7 +7,7 @@ log:
|
|||||||
- transaction_id
|
- transaction_id
|
||||||
- message_id
|
- message_id
|
||||||
- subscriber_id
|
- subscriber_id
|
||||||
- module_name
|
- module_id
|
||||||
http:
|
http:
|
||||||
port: 8080
|
port: 8080
|
||||||
timeout:
|
timeout:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ log:
|
|||||||
- transaction_id
|
- transaction_id
|
||||||
- message_id
|
- message_id
|
||||||
- subscriber_id
|
- subscriber_id
|
||||||
- module_name
|
- module_id
|
||||||
http:
|
http:
|
||||||
port: 8080
|
port: 8080
|
||||||
timeout:
|
timeout:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ log:
|
|||||||
- transaction_id
|
- transaction_id
|
||||||
- message_id
|
- message_id
|
||||||
- subscriber_id
|
- subscriber_id
|
||||||
- module_name
|
- module_id
|
||||||
http:
|
http:
|
||||||
port: 8080
|
port: 8080
|
||||||
timeout:
|
timeout:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/beckn/beckn-onix/core/module/handler"
|
"github.com/beckn/beckn-onix/core/module/handler"
|
||||||
"github.com/beckn/beckn-onix/pkg/log"
|
"github.com/beckn/beckn-onix/pkg/log"
|
||||||
|
"github.com/beckn/beckn-onix/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config represents the configuration for a module.
|
// Config represents the configuration for a module.
|
||||||
@@ -75,7 +76,7 @@ func addMiddleware(ctx context.Context, mgr handler.PluginManager, handler http.
|
|||||||
|
|
||||||
func moduleCtxMiddleware(moduleName string, next http.Handler) http.Handler {
|
func moduleCtxMiddleware(moduleName string, next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := context.WithValue(r.Context(), "module_name", moduleName)
|
ctx := context.WithValue(r.Context(), model.ContextKeyModuleId, moduleName)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/beckn/beckn-onix/core/module/handler"
|
"github.com/beckn/beckn-onix/core/module/handler"
|
||||||
|
"github.com/beckn/beckn-onix/pkg/model"
|
||||||
"github.com/beckn/beckn-onix/pkg/plugin"
|
"github.com/beckn/beckn-onix/pkg/plugin"
|
||||||
"github.com/beckn/beckn-onix/pkg/plugin/definition"
|
"github.com/beckn/beckn-onix/pkg/plugin/definition"
|
||||||
)
|
)
|
||||||
@@ -106,7 +107,7 @@ func TestRegisterSuccess(t *testing.T) {
|
|||||||
// Create a handler that extracts context
|
// Create a handler that extracts context
|
||||||
var capturedModuleName any
|
var capturedModuleName any
|
||||||
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
capturedModuleName = r.Context().Value("module_name")
|
capturedModuleName = r.Context().Value(model.ContextKeyModuleId)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ func TestRegisterSuccess(t *testing.T) {
|
|||||||
|
|
||||||
// Now verify if module name exists in context
|
// Now verify if module name exists in context
|
||||||
if capturedModuleName != "test-module" {
|
if capturedModuleName != "test-module" {
|
||||||
t.Errorf("expected module_name in context to be 'test-module', got %v", capturedModuleName)
|
t.Errorf("expected module_id in context to be 'test-module', got %v", capturedModuleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package model
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ type Subscriber struct {
|
|||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContextKey string
|
||||||
|
|
||||||
|
const ContextKeyModuleId ContextKey = "module_id"
|
||||||
|
|
||||||
// Subscription represents subscription details of a network participant.
|
// Subscription represents subscription details of a network participant.
|
||||||
type Subscription struct {
|
type Subscription struct {
|
||||||
Subscriber `json:",inline"`
|
Subscriber `json:",inline"`
|
||||||
|
|||||||
Reference in New Issue
Block a user