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

feat(middleware): add sunset/deprecation header middleware #844

Merged
merged 3 commits into from Oct 19, 2023

Conversation

thedevsaddam
Copy link
Contributor

@thedevsaddam thedevsaddam commented Sep 4, 2023

This PR will include a Sunset middleware which can be used to deprecate an endpoint or a group of endpoints.

For additional information please go through the LINK

Example usages

func main() {
	r := chi.NewRouter()

	sunsetAt := time.Date(2025, 12, 24, 10, 20, 0, 0, time.UTC)
	r.Use(middleware.Sunset(sunsetAt))

	// can provide additional link for updated resource
	// r.Use(middleware.Sunset(sunsetAt, "https://example.com/v1/deprecation-details"))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("This endpoint will be removed soon"))
	})

	log.Println("Listening on port: 3000")
	http.ListenAndServe(":3000", r)
}

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature. However, should we wait for the Sunset header to actually make it into an RFC?

middleware/sunset.go Outdated Show resolved Hide resolved
middleware/sunset.go Outdated Show resolved Hide resolved
middleware/sunset.go Outdated Show resolved Hide resolved
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I think this is useful, especially since these headers are defined in RFC8594 - https://www.rfc-editor.org/rfc/rfc8594.html.

Let's see if @pkieltyka agrees this can be merged into github.com/go-chi/chi/v5/middleware :)

Respect previously added links as this header can be used by other
components
@pkieltyka
Copy link
Member

thanks for the PR @thedevsaddam and thanks for reviewing @VojtechVitek

@pkieltyka pkieltyka merged commit 3954a76 into go-chi:master Oct 19, 2023
14 checks passed
@thedevsaddam
Copy link
Contributor Author

thanks for the PR @thedevsaddam and thanks for reviewing @VojtechVitek

Thank you so much for this amazing package!

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.

None yet

3 participants