Skip to content

Instantly share code, notes, and snippets.

@abiosoft
Created June 18, 2017 05:35
Show Gist options
  • Save abiosoft/2cf3aadb617c6a1ba31ed00fb46f0477 to your computer and use it in GitHub Desktop.
Save abiosoft/2cf3aadb617c6a1ba31ed00fb46f0477 to your computer and use it in GitHub Desktop.
webapp with static dir
package main
import (
"fmt"
"net/http"
)
func main() {
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", handler)
fmt.Println("Listening on 8888")
http.ListenAndServe(":8888", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
Hello world
<div>
This should be styled
</div>
</body>
</html>
`))
}
/* save this in static/style.css */
div {
font-size: 12px;
font-family: monospace;
text-decoration: underline;
}
div:hover {
cursor: pointer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment