-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgoCal.go
74 lines (60 loc) · 1.7 KB
/
goCal.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"net/http"
"simonwaldherr.de/go/caldav-go/files"
"simonwaldherr.de/go/golibs/file"
"simonwaldherr.de/go/gwv"
)
var (
SSLCert string
SSLKey string
UserFile string
StoragePath string
HTTPPort int
HTTPSPort int
)
var userdata map[string]userData
func init() {
flag.StringVar(&SSLCert, "sslcrt", "ssl.crt", "path to the ssl/tls crt file")
flag.StringVar(&SSLKey, "sslkey", "ssl.key", "path to the ssl/tls key file")
flag.StringVar(&UserFile, "user", "user.csv", "path to the user.csv file")
flag.StringVar(&StoragePath, "storage", "icsdata", "path to the folder with ics data")
flag.IntVar(&HTTPPort, "port", 80, "http port to listen")
flag.IntVar(&HTTPSPort, "sport", 443, "https port to listen")
flag.Parse()
userdata = loadUserDataFromFile(UserFile)
files.StoragePath = StoragePath
}
func main() {
if !file.Exists(SSLCert) || !file.Exists(SSLKey) {
options := map[string]string{}
options["certPath"] = SSLCert
options["keyPath"] = SSLKey
options["host"] = "*"
options["countryName"] = "DE"
options["provinceName"] = "Bavaria"
options["organizationName"] = "Lorem Ipsum Ltd"
options["commonName"] = "*"
gwv.GenerateSSL(options)
}
startServer()
}
func caldavhandler(rw http.ResponseWriter, req *http.Request) (string, int) {
CalDAVHandler(rw, req)
return "", 0
}
func feedhandler(rw http.ResponseWriter, req *http.Request) (string, int) {
FeedHandler(rw, req)
return "", 0
}
func startServer() {
HTTPD := gwv.NewWebServer(HTTPPort, 60)
HTTPD.ConfigSSL(HTTPSPort, SSLKey, SSLCert, true)
HTTPD.URLhandler(
gwv.URL("^/icsfeed/", feedhandler, gwv.MANUAL),
gwv.URL("^/", caldavhandler, gwv.MANUAL),
)
HTTPD.Start()
HTTPD.WG.Wait()
}