-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpd-srv.go
55 lines (45 loc) · 1.06 KB
/
httpd-srv.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
48
49
50
51
52
53
54
55
package opnborg
import (
"fmt"
"net/http"
"os"
)
// httpd spinup the http internal web server
func startWeb(config *OPNCall) {
// terminate if not in daemon mode
if !config.Daemon {
return
}
// create store structure
if err := os.MkdirAll(config.Path, 0770); err != nil {
fmt.Println(err)
return
}
// change thread into store-root
if err := os.Chdir(config.Path); err != nil {
fmt.Println(err)
return
}
// get listener, bind ports
listener, err := getHTTPTLS(config)
if err != nil {
fmt.Println(err)
return
}
// setup mux
mux := http.NewServeMux()
// handler
mux.Handle("/", addSecurityHeader(getIndexHandler()))
mux.Handle("/gitlog/", addSecurityHeader(getGitHandler()))
mux.Handle("/files/", addSecurityHeader(http.StripPrefix("/files/", http.FileServer(http.Dir(config.Path)))))
// httpsrv
httpsrv := &http.Server{
Handler: mux,
}
// info
if config.Debug {
displayChan <- []byte("[HTTPD-SRV][SPIN-UP-SERVER] " + config.Httpd.Server)
}
// serve requestes, print err after httpd crash
fmt.Println(httpsrv.Serve(listener))
}