-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.07 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
48
49
50
51
package main
import (
"fmt"
"net/http"
"os"
)
// Path where the snapshot files go.
var cfgBasePath string = checkEnvUnset("OC_REL_BASE_PATH")
// Path where the HTML pages go.
var cfgHtmlPath string = checkEnvUnset("OC_REL_HTML_PATH")
// Authentication data in the format <username>:<password> (basic auth)
var cfgUploadPassword string = checkEnvUnset("OC_REL_UPLOAD_PASSWORD")
// Port to listen on.
var cfgPort string = checkEnvUnset("PORT")
func main() {
updateStaticFiles()
http.HandleFunc("/snapshots/", handleSnapshots)
fmt.Println("listening on", cfgPort)
err := http.ListenAndServe(cfgPort, nil)
if err != nil {
fmt.Println("listen failed:", err)
os.Exit(2)
}
}
func checkEnvUnset(env string) string {
s := os.Getenv(env)
if s == "" {
fmt.Println("error:", env, "required but not set")
os.Exit(1)
}
return s
}
func updateStaticFiles() {
if err := os.MkdirAll(cfgHtmlPath+"/snapshots", 0755); err != nil {
fmt.Println("error: could not prepare HTML directory: ", err)
return
}
generateSnapshotPage()
createLatestLinks()
generateSnapshotVersionInfo()
}