Serving content using ServeMux

suggest change

A simple static file server would look like this:

package main

import (
    "net/http"
)

func main() {
    muxer := http.NewServeMux()
    fileServerCss := http.FileServer(http.Dir("src/css"))
    fileServerJs := http.FileServer(http.Dir("src/js"))
    fileServerHtml := http.FileServer(http.Dir("content"))
    muxer.Handle("/", fileServerHtml)
    // A pattern ending in "/" is a subtree. StripPrefix removes that prefix
    // so the file server looks up css/site.css as src/css/site.css.
    muxer.Handle("/css/", http.StripPrefix("/css/", fileServerCss))
    muxer.Handle("/js/", http.StripPrefix("/js/", fileServerJs))
    http.ListenAndServe(":8080", muxer)
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents