Skip to content

Easily manage routes and handlers on top of *http.ServeMux.

License

Notifications You must be signed in to change notification settings

mariomenjr/handlr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e616c4f · May 3, 2022

History

26 Commits
Apr 29, 2022
Apr 10, 2022
Apr 10, 2022
Apr 23, 2022
Apr 10, 2022
May 3, 2022
Apr 23, 2022
Apr 25, 2022
May 3, 2022
Apr 27, 2022
May 3, 2022
May 3, 2022
May 3, 2022
Apr 25, 2022

Repository files navigation

mariomenjr/handlr

GoDoc CircleCI

Easily manage routes and handlers on top of *http.ServeMux.


Install

As you would do with almost any other Go package.

go get -u github.com/mariomenjr/handlr

Examples

Handlers

You can register paths and handlers directly:

// main.go

func main() {
	h := handlr.New()

	h.HandleFunc("/feed", feedHandler)

	r.Start(1993)
}

func feedHandler(w http.ResponseWriter, r *http.Request) {
	// ...
}

Routes

You can also register Routes which allow you to organize your handlers (or even sub-Routes) into multiple files in an elegant way.

├── main.go
├── feed.route.go
├── acccount.route.go
// main.go

func main() {
	h := handlr.New()

	h.RouteFunc("/feed", feedRoute)
	h.RouteFunc("/account", accountRoute)
	
	r.Start(1993)
}
// feed.route.go

func feedRoute(r *handlr.Router) {
	r.HandleFunc("/latest", latestHandler)

	r.RouteFunc("/custom", feedCustomRoute)
}

func latestHandler(w http.ResponseWriter, r *http.Request) {
	// ...
}

func feedCustomRoute(r *handlr.Router) {
	r.HandleFunc("/monthly", feedCustomMonthlyHandler)
}

func feedCustomMonthlyHandler(w http.ResponseWriter, r *http.Request) {
	// ...
}
// account.route.go

func accountRoute(r *handlr.Router) {
	r.HandleFunc("/profile", accountProfileHandlr)
	r.HandleFunc("/settings", accountSettingsHandlr)
}

func accountProfileHandlr(w http.ResponseWriter, r *http.Request) {
	// ...
}

func accountSettingsHandlr(w http.ResponseWriter, r *http.Request) {
	// ...
}

License

The source code of this project is under MIT License.

About

Easily manage routes and handlers on top of *http.ServeMux.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages