-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 1.13 KB
/
main.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"
log "github.com/sirupsen/logrus"
"net"
"net/http"
"net/http/fcgi"
)
func main() {
address := flag.String("a", "127.0.0.1:9000", "address to listen on")
rootPath := flag.String("d", "/var/www/html/", "directory to serve from")
index := flag.String("i", "index.gohtml", "filename of directory indexes")
logLevel := flag.String("loglevel", "info", "one of: panic, fatal, error, warn, info, debug, trace")
flag.Parse()
ll, err := log.ParseLevel(*logLevel)
if err != nil {
log.Fatalf("Invalid log level '%s'. Exiting...", *logLevel)
return
}
log.SetLevel(ll)
log.Info("Starting GHP...")
root := http.Dir(*rootPath)
server, err := IndexServer(root, *index, NewIndexViewmodel)
if err != nil {
log.Fatal(err.Error())
return
}
log.Infof("Serving directory \"%s\"", *rootPath)
listener, err := net.Listen("tcp", *address)
if err != nil {
log.Fatalf("Couldn't listen on %s: %s", *address, err.Error())
return
}
log.Infof("Listening on %s", *address)
if err := fcgi.Serve(listener, server); err != nil {
log.Fatalf("Fatal error while listening on %s: %s", *address, err.Error())
return
}
}