Created
June 18, 2017 05:35
-
-
Save abiosoft/2cf3aadb617c6a1ba31ed00fb46f0477 to your computer and use it in GitHub Desktop.
webapp with static dir
This file contains 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 ( | |
"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> | |
`)) | |
} |
This file contains 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
/* 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