I have a map
in Go with routes (e.g. /static/stylesheets/main.css
) as keys and the corresponding code as the value (effectively, a giant string). I was just wondering, is there an easy way in Go by which I can create an HTTP server, which always check an incoming request against the map
and renders the value associated with the matched key, if the key exists?
So far, I have...
func main() {
var m = generateMap()
http.handleFunc("/", renderContent);
}
func renderContent(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, m[path]);
}
I know this code is far from done, but hopefully it clarifies my objective. How would I pass in the path
and m
into renderContent
as well as how do I have handleFunc
actually handle regexes (essentially, any path)?