Skip to content

Strict Server Middlewares are hard to reuse.  #766

Closed as not planned
Closed as not planned

Description

@ralf-cestusio
type StrictHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, args interface{}) (interface{}, error)

type StrictMiddlewareFunc func(f StrictHandlerFunc, operationID string) StrictHandlerFunc

Types are generated with the api and are part of the package of the api.

This makes it very difficult to reuse a middleware

I would suggest to add them to a part of the library and reuse them as part of the generated code.

Activity

  1. johanneswuerbach commented on Feb 6, 2023

    @johanneswuerbach
    Contributor

    After testing different options, the following workaround seems to work:

    func MyMiddleware[K ~func(ctx echo.Context, args interface{}) (interface{}, error)](f K, operationID string) K {
    	return func(ctx echo.Context, args interface{}) (interface{}, error) {
    		// code
    		return f(ctx, args)
    	}
    }

    and used using:

    NewStrictHandler(s, []StrictMiddlewareFunc{
    	MyMiddleware[StrictHandlerFunc],
    })

    Not pretty, but it works :-)

  2. mromaszewicz commented on May 1, 2026

    @mromaszewicz
    Member

    PR #1021 (commit 844e5db) extracted the strict middleware types to runtime/strictmiddleware/* packages to address this issue. However, commit 5b562c4 (by the maintainer) deliberately reversed that approach, inlining the types back into each generated package and closing issue #2270. This is an explicit design decision: types are local per-package. A generic-based workaround exists (described in the issue comments). The issue is superseded by the intentional wontfix choice.

    Closing — not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions