command line args

This commit is contained in:
Chapuis Bertil
2015-09-07 15:29:24 +02:00
parent 436de7f687
commit 738e78c439
6 changed files with 110 additions and 74 deletions

View File

@@ -1,19 +1,31 @@
package main
import (
//"io/ioutil"
"flag"
"log"
"net/http"
"path/filepath"
)
const (
HTTP = ":8000"
HTTPS = ":8443"
)
func main() {
context := NewContext("/tmp/restic")
repo, _ := context.Repository("user")
repo.Init()
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()
context := NewContext(*path)
router := Router{context}
port := ":8000"
log.Printf("start server on port %s", port)
http.ListenAndServe(port, router)
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")
http.ListenAndServeTLS(HTTPS, privateKey, publicKey, router)
}
}