feat: added role for bap and bpp

This commit is contained in:
mayur.popli
2025-03-21 04:44:58 +05:30
parent 5e3422fb24
commit 02fb7c0897
2 changed files with 38 additions and 43 deletions

View File

@@ -14,11 +14,12 @@ import (
type Config struct {
checkKeys []string
Role string
}
type contextKeyType string
const contextKey = "context"
const subscriberIDKey contextKeyType = "subscriber_id"
func NewUUIDSetter(cfg *Config) (func(http.Handler) http.Handler, error) {
if err := validateConfig(cfg); err != nil {
@@ -47,7 +48,14 @@ func NewUUIDSetter(cfg *Config) (func(http.Handler) http.Handler, error) {
http.Error(w, fmt.Sprintf("%s field is not a map.", contextKey), http.StatusBadRequest)
return
}
ctx := r.Context()
var subID any
switch cfg.Role {
case "bap":
subID = contextData["bap_id"]
case "bpp":
subID = contextData["bpp_id"]
}
ctx := context.WithValue(r.Context(), subscriberIDKey, subID)
for _, key := range cfg.checkKeys {
value := uuid.NewString()
updatedValue := update(contextData, key, value)
@@ -90,9 +98,6 @@ func validateConfig(cfg *Config) error {
if cfg == nil {
return errors.New("config cannot be nil")
}
if len(cfg.checkKeys) == 0 {
return errors.New("checkKeys cannot be empty")
}
for _, key := range cfg.checkKeys {
if key == "" {
return errors.New("checkKeys cannot contain empty strings")