Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "io"
- "log"
- "net/http"
- "os"
- )
- func serveStatic(resp http.ResponseWriter, req *http.Request) {
- path := req.URL.Path[1:]
- if file, err := os.Open(path); err == nil {
- io.Copy(resp, file)
- file.Close()
- } else {
- resp.WriteHeader(http.StatusNotFound)
- io.WriteString(resp, path + ": not found")
- }
- }
- func main() {
- http.HandleFunc("/", serveStatic)
- log.Fatal(http.ListenAndServe(":8080", nil))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement