In this recipe, we are going to create a file server that will serve static resources from the filesystem. Perform the following steps:
- Create main.css inside a static/css directory, as follows:
$ mkdir static && cd static && mkdir css && cd css && touch main.css
- Copy the following content to main.css:
body {color: #00008B}
- Create serve-static-files.go, where we will create FileServer, which will serve resources from the static/css directory present on the filesystem for all URL patterns with /static, as follows:
package mainimport ( "fmt" "html/template" "log" "net/http")const ( CONN_HOST = "localhost" CONN_PORT = "8080")type Person struct { Name string Age string}func renderTemplate(w http.ResponseWriter, r *http.Request) ...