-
Notifications
You must be signed in to change notification settings - Fork 0
/
webdav-server.go
59 lines (50 loc) · 1.42 KB
/
webdav-server.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
package main
import (
"crypto/tls"
"fmt"
"net/http"
"os"
"github.com/Pilladian/go-helper"
"github.com/Pilladian/logger"
"golang.org/x/net/webdav"
)
// GLOBAL VARS
var STORAGE_PATH string = "./data"
var SERVER_PORT int = 8080
var WEBDAV_SERVER *webdav.Handler
var AUTH_USERS map[string]string
var CLIENT *http.Client
var INFOWATCH_PID = os.Getenv("INFOWATCH_PID")
var ELASTIC_SEARCH_PID = os.Getenv("ELASTIC_SEARCH_PID")
// initialize environment
func initialize() {
logger.SetLogLevel(2)
if create_path_err := helper.CreatePath(STORAGE_PATH); create_path_err != nil {
logger.Error(create_path_err.Error())
}
// add authorized users
AUTH_USERS = make(map[string]string)
AUTH_USERS[os.Getenv("USERNAME")] = os.Getenv("PASSWORD")
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
CLIENT = &http.Client{}
}
// entrypoint
func main() {
initialize()
WEBDAV_SERVER = &webdav.Handler{
FileSystem: webdav.Dir(STORAGE_PATH),
LockSystem: webdav.NewMemLS(),
Logger: func(r *http.Request, err error) {
if err != nil {
logger.Error(fmt.Sprintf("%s : %s : %s", r.Method, r.URL, err))
}
},
}
logger.Info("starting webdav server")
http.HandleFunc("/", handleRequests)
http.HandleFunc("/healthy", healthyRequestHandler)
http_server_err := http.ListenAndServe(fmt.Sprintf(":%d", SERVER_PORT), nil)
if http_server_err != nil {
logger.Error(http_server_err.Error())
}
}