Skip to content

Conversation

@karitham
Copy link
Collaborator

@karitham karitham commented Sep 5, 2022

This PR cleans up the ugly middleware map in favor of a clean, generated struct.

The goal is to profit from the excellent autocompletion provided by IDEs to work faster.

As an added bonus, if you had previously used a middleware and forgot it in the spec, the code wont compile, as opposed to silently running, ensuring not ever forgetting a middleware both in the code and in the spec (If you've never typed it, I can't do anything for you)

@karitham karitham marked this pull request as ready for review September 5, 2022 14:52
@karitham karitham requested a review from hhhapz September 5, 2022 14:52
@karitham karitham changed the title implement const middleware names generation Generate middlewares as fields Sep 8, 2022
@karitham
Copy link
Collaborator Author

karitham commented Sep 8, 2022

Before:

	mw := map[string]func(http.Handler) http.Handler{
		"pathMiddleware": func(h http.Handler) http.Handler {
			called = true
			return h
		},
		"operationMiddleware": func(h http.Handler) http.Handler { return h },
	}

After:

	mw := Middlewares{
		Path: func(h http.Handler) http.Handler {
			called = true
			return h
		},
		Operation: func(h http.Handler) http.Handler { return h },
	}

@karitham karitham force-pushed the generate-middleware-const branch from 066ee08 to 6ec216f Compare September 8, 2022 16:19
@karitham karitham force-pushed the generate-middleware-const branch 2 times, most recently from fec1ff1 to b500925 Compare June 12, 2023 10:40
karitham added 6 commits June 12, 2023 12:45
Avoids having to deal with raw strings
Also generate middleware stuff only when a middleware is ever defined,
leaner code, no hanging types
@karitham karitham force-pushed the generate-middleware-const branch from 63625ea to b0e1ca6 Compare June 12, 2023 10:46
@karitham karitham force-pushed the generate-middleware-const branch from b0e1ca6 to 75726cf Compare June 12, 2023 10:46
@karitham karitham merged commit f399b26 into main Jun 12, 2023
@karitham karitham deleted the generate-middleware-const branch June 12, 2023 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants