Created
December 7, 2019 13:36
-
-
Save ichtrojan/45c0ecf569af1a84111e846d62cc4552 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gorilla/mux" | |
"html/template" | |
"log" | |
"net/http" | |
) | |
func main () { | |
route := mux.NewRouter() | |
http.FileServer(http.Dir("/public")) | |
route.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { | |
view, err := template.ParseFiles("views/errors/404.html") | |
if err != nil { | |
log.Fatal(err) | |
} | |
_ = view.Execute(writer, nil) | |
}) | |
err := http.ListenAndServe(":9000", route) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works. You need to have a public directory directly at the same level in the filesystem as the binary you are running. So if a file is in
./public/css/index.css
, it will be accessed by<a href="/assets/css/index.css">