2015-08-11 14:14:07 +02:00
|
|
|
package main
|
|
|
|
|
2015-08-15 10:06:10 +02:00
|
|
|
import (
|
2015-09-07 15:29:24 +02:00
|
|
|
"flag"
|
2015-08-15 10:06:10 +02:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2015-09-07 15:29:24 +02:00
|
|
|
"path/filepath"
|
2015-08-15 10:06:10 +02:00
|
|
|
)
|
2015-08-11 14:14:07 +02:00
|
|
|
|
2015-09-07 15:29:24 +02:00
|
|
|
const (
|
|
|
|
HTTP = ":8000"
|
|
|
|
HTTPS = ":8443"
|
|
|
|
)
|
2015-08-15 10:06:10 +02:00
|
|
|
|
2015-09-07 15:29:24 +02:00
|
|
|
func main() {
|
|
|
|
var path = flag.String("path", "/tmp/restic", "specifies the path of the data directory")
|
|
|
|
var tls = flag.Bool("tls", false, "turns on tls support")
|
|
|
|
flag.Parse()
|
2015-08-15 10:06:10 +02:00
|
|
|
|
2015-09-07 15:29:24 +02:00
|
|
|
context := NewContext(*path)
|
2015-08-15 10:06:10 +02:00
|
|
|
router := Router{context}
|
2015-09-07 15:29:24 +02:00
|
|
|
if !*tls {
|
|
|
|
log.Printf("start server on port %s", HTTP)
|
|
|
|
http.ListenAndServe(HTTP, router)
|
|
|
|
} else {
|
|
|
|
log.Printf("start server on port %s", HTTPS)
|
|
|
|
privateKey := filepath.Join(*path, "private_key")
|
|
|
|
publicKey := filepath.Join(*path, "public_key")
|
2015-09-07 16:17:24 +02:00
|
|
|
|
|
|
|
log.Printf("private key: %s", privateKey)
|
|
|
|
log.Printf("public key: %s", publicKey)
|
|
|
|
http.ListenAndServeTLS(HTTPS, publicKey, privateKey, router)
|
2015-09-07 15:29:24 +02:00
|
|
|
}
|
2015-08-11 14:14:07 +02:00
|
|
|
}
|