mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
command line args
This commit is contained in:
28
server.go
28
server.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user