-
Notifications
You must be signed in to change notification settings - Fork 0
/
goserve.go
31 lines (27 loc) · 1.06 KB
/
goserve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (C) 2018 Robert A. Wallis, All Rights Reserved
// goserve is a very simple localhost:8000 static file server, for developing static sites.
//
// Usage: run `goserve` in a folder. It's files will be available at http://localhost:8000/
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var g_bind = flag.String("bind", "localhost:8000", "server binding")
var g_corp = flag.String("corp", "same-site", "Cross-Origin-Resource-Policy \"same-site\" | \"cross-origin\"")
func main() {
flag.Parse()
var fileServer = http.FileServer(http.Dir("."))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.RequestURI, r.RemoteAddr)
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Cross-Origin-Resource-Policy", *g_corp)
w.Header().Set("Cross-Origin-Opener-Policy", "same-origin")
w.Header().Set("Cross-Origin-Embedder-Policy", "require-corp")
fileServer.ServeHTTP(w, r)
})
fmt.Printf("Listening at http://%s\n", *g_bind)
log.Fatal(http.ListenAndServe(*g_bind, nil))
}