Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggerWithFormatter missing 2nd param #29

Open
idc77 opened this issue Mar 7, 2023 · 1 comment
Open

LoggerWithFormatter missing 2nd param #29

idc77 opened this issue Mar 7, 2023 · 1 comment

Comments

@idc77
Copy link

idc77 commented Mar 7, 2023

This used to work

		oidcHandler := nethttpoidc.New(srv,
			options.WithIssuer(cfg.Issuer),
			options.WithRequiredTokenType("JWT"),
			options.WithRequiredAudience(cfg.Audience),
			options.IsPermissive(),
		)
		corshandler := cors.AllowAll()

		s := corshandler.Handler(
			httplog.LoggerWithFormatter(
				httplog.DefaultLogFormatterWithRequestHeader,
				oidcHandler,
			))

		return http.ListenAndServe(serveAddr, s)

now it doesn't anymore

Cannot use 'httplog.LoggerWithFormatter( httplog.DefaultLogFormatterWithRequestHeader, oidcHandler, )' (type func(next http.Handler) http.Handler) as the type http.Handler Type does not implement 'http.Handler' as some methods are missing: ServeHTTP(ResponseWriter, *Request)

github.com/MadAppGang/httplog v1.3.0
previous version v1.2.1

@erudenko
Copy link
Member

erudenko commented Mar 9, 2023

Hi, sorry for the inconvenience.

Now it is simpler and you have two options:

You can user httplog.HandlerWithFormatter:

		s := corshandler.Handler(
			httplog.HandlerWithFormatter(
				httplog.DefaultLogFormatterWithRequestHeader,
				oidcHandler,
			))

Because Logger with formatted now returns logger middleware, you can reuse, the code will look something like that:

		oidcHandler := nethttpoidc.New(srv,
			options.WithIssuer(cfg.Issuer),
			options.WithRequiredTokenType("JWT"),
			options.WithRequiredAudience(cfg.Audience),
			options.IsPermissive(),
		)
                logger := httplog.LoggerWithFormatter(httplog.DefaultLogFormatterWithRequestHeader)
		corshandler := cors.AllowAll()

		s := corshandler.Handler(logger(oidcHandler))

		return http.ListenAndServe(serveAddr, s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

2 participants