-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
33 lines (28 loc) · 785 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var configPath string
var certPath string
var privKeyPath string
var port int
func main() {
flag.StringVar(&configPath, "config", "doer.json", "Path to a config file")
flag.StringVar(&certPath, "cert", "", "Path to a certificate file")
flag.StringVar(&privKeyPath, "key", "", "Path to a private key")
flag.IntVar(&port, "port", 8778, "Port to listen on")
flag.Parse()
config := loadConfig(configPath)
server := Server{config}
addr := fmt.Sprintf(":%d", port)
if certPath == "" {
log.Println("Starting the server with plain HTTP on", addr)
http.ListenAndServe(addr, &server)
} else {
log.Println("Starting the server with HTTPS on", addr)
http.ListenAndServeTLS(addr, certPath, privKeyPath, &server)
}
}