4 ms·
I built a small site in Go and I didn't really see the need to use a framework. Here's what I did for routes. func getRoutes() map[string]customHndlrFnc {
by learc83 13y ago
I built a small site in Go and I didn't really see the need to use a framework. Here's what I did for routes.
func getRoutes() map[string]customHndlrFnc {
r := make(map[string]customHndlrFnc)
//routes
r["/route_to_url"] = handler
r["/route_to_url2"] = handler2
return r
}
for key, value := range getRoutes() {
http.HandleFunc(key, handlerWrapper(value))
}
All of my routes for this sample were get requests but it could easily be extended.
- james4k 13y agoWhy do that versus: http.HandleFunc("/route_to_url", handlerWrapper(handler)) http.HandleFunc("/route_to_url2", handlerWrapper(handler2)) Is the map used elsewhere?