fix: resolved comments

This commit is contained in:
mayur.popli
2025-04-04 16:34:43 +05:30
parent 67808f3628
commit bb737505d4
4 changed files with 5 additions and 8 deletions

View File

@@ -51,7 +51,7 @@ func Register(ctx context.Context, mCfgs []Config, mux *http.ServeMux, mgr handl
} }
// addMiddleware applies middleware plugins to the provided handler in reverse order. // addMiddleware applies middleware plugins to the provided handler in reverse order.
// It retrieves middleware instances from the plugin manager and chains them to the handler.. // It retrieves middleware instances from the plugin manager and chains them to the handler.
func addMiddleware(ctx context.Context, mgr handler.PluginManager, handler http.Handler, hCfg *handler.Config) (http.Handler, error) { func addMiddleware(ctx context.Context, mgr handler.PluginManager, handler http.Handler, hCfg *handler.Config) (http.Handler, error) {
mws := hCfg.Plugins.Middleware mws := hCfg.Plugins.Middleware
log.Debugf(ctx, "Applying %d middleware(s) to the handler", len(mws)) log.Debugf(ctx, "Applying %d middleware(s) to the handler", len(mws))

View File

@@ -99,7 +99,7 @@ func TestRegisterSuccess(t *testing.T) {
} }
} }
// TestRegisterFailure tests scenarios where the handler registration should fail.. // TestRegisterFailure tests scenarios where the handler registration should fail.
func TestRegisterFailure(t *testing.T) { func TestRegisterFailure(t *testing.T) {
tests := []struct { tests := []struct {
name string name string

View File

@@ -105,16 +105,13 @@ func (v *schemaValidator) Validate(ctx context.Context, url *url.URL, data []byt
// Return the array of schema validation errors // Return the array of schema validation errors
return &model.SchemaValidationErr{Errors: schemaErrors} return &model.SchemaValidationErr{Errors: schemaErrors}
} }
return model.NewBadReqErr(fmt.Errorf("validation failed: %v", err)) return fmt.Errorf("validation failed: %v", err)
} }
// Return nil if validation succeeds // Return nil if validation succeeds
return nil return nil
} }
// ValidatorProvider provides instances of Validator.
type ValidatorProvider struct{}
// Initialise initialises the validator provider by compiling all the JSON schema files // Initialise initialises the validator provider by compiling all the JSON schema files
// from the specified directory and storing them in a cache indexed by their schema filenames. // from the specified directory and storing them in a cache indexed by their schema filenames.
func (v *schemaValidator) initialise() error { func (v *schemaValidator) initialise() error {

View File

@@ -33,7 +33,7 @@ func New(ctx context.Context, config *Config) (*validator, func() error, error)
func (v *validator) Validate(ctx context.Context, body []byte, header string, publicKeyBase64 string) error { func (v *validator) Validate(ctx context.Context, body []byte, header string, publicKeyBase64 string) error {
createdTimestamp, expiredTimestamp, signature, err := parseAuthHeader(header) createdTimestamp, expiredTimestamp, signature, err := parseAuthHeader(header)
if err != nil { if err != nil {
return model.NewBadReqErr(fmt.Errorf("error parsing header: %w", err)) return model.NewSignValidationErr(fmt.Errorf("error parsing header: %w", err))
} }
signatureBytes, err := base64.StdEncoding.DecodeString(signature) signatureBytes, err := base64.StdEncoding.DecodeString(signature)
@@ -53,7 +53,7 @@ func (v *validator) Validate(ctx context.Context, body []byte, header string, pu
decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKeyBase64) decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKeyBase64)
if err != nil { if err != nil {
return model.NewBadReqErr(fmt.Errorf("error decoding public key: %w", err)) return model.NewSignValidationErr(fmt.Errorf("error decoding public key: %w", err))
} }
if !ed25519.Verify(ed25519.PublicKey(decodedPublicKey), []byte(signingString), signatureBytes) { if !ed25519.Verify(ed25519.PublicKey(decodedPublicKey), []byte(signingString), signatureBytes) {