-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrvHttpd.go
60 lines (48 loc) · 1.21 KB
/
srvHttpd.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
56
57
58
59
60
package opnborg
import (
"fmt"
"net/http"
"os"
githttp "github.com/AaronO/go-git-http"
)
// httpd spinup the http internal web server
func startWeb(c *OPNCall) {
// create store structure
if err := os.MkdirAll(c.Path, 0770); err != nil {
fmt.Println(err)
return
}
// change thread into store-root
if err := os.Chdir(c.Path); err != nil {
fmt.Println(err)
return
}
// get listener, bind ports
listener, err := getHTTPTLS(c)
if err != nil {
fmt.Println(err)
return
}
// setup mux
mux := http.NewServeMux()
// handler
mux.Handle("/", addSecurityHeader(getIndexHandler()))
mux.Handle("/files/", addSecurityHeader(http.StripPrefix("/files/", http.FileServer(http.Dir(c.Path)))))
mux.Handle("/force", getForceHandler())
mux.Handle("/favicon.ico", getFavIconHandler())
// spin up internal git repo https server
state := "[DISABLED]"
if c.GitSrv.Enable {
mux.Handle("/git", githttp.New(c.Path))
state = "[ENABLED]"
}
displayChan <- []byte("[GITSRV-HTTP]" + state)
// httpsrv
httpsrv := &http.Server{
Handler: mux,
}
// info
displayChan <- []byte("[HTTPD-SRV][SPIN-UP-SERVER] " + c.Httpd.Server)
// serve requestes, print err after httpd crash
fmt.Println(httpsrv.Serve(listener))
}