/
test.go
47 lines (40 loc) · 912 Bytes
/
test.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"io"
"log"
"net/http"
"os"
"runtime/pprof"
useful "github.com/EricLagerg/UsefulHandler"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
io.WriteString(w, "Hello, world!")
})
opts := useful.Options{
Logger: useful.NCSALog,
Destination: useful.Both,
ArchiveDir: "archives",
LogName: "access.log",
MaxFileSize: 2 * useful.Megabyte,
}
myHandler := useful.NewUsefulHandler(handler, opts)
http.Handle("/", myHandler)
server := http.Server{
Addr: ":1234",
Handler: nil,
}
server.ListenAndServe()
}