Added flags for supplying certificate/key and TLS listener option.
This commit is contained in:
parent
70732c341a
commit
a3f617abad
1 changed files with 26 additions and 2 deletions
|
@ -34,6 +34,10 @@ var (
|
||||||
// driver specific connection information. In this
|
// driver specific connection information. In this
|
||||||
// case, it should be the location of the SQLite file
|
// case, it should be the location of the SQLite file
|
||||||
datasource string
|
datasource string
|
||||||
|
|
||||||
|
// optional flags for tls listener
|
||||||
|
sslcert string
|
||||||
|
sslkey string
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -42,15 +46,35 @@ func main() {
|
||||||
flag.StringVar(&port, "port", ":8080", "")
|
flag.StringVar(&port, "port", ":8080", "")
|
||||||
flag.StringVar(&driver, "driver", "sqlite3", "")
|
flag.StringVar(&driver, "driver", "sqlite3", "")
|
||||||
flag.StringVar(&datasource, "datasource", "drone.sqlite", "")
|
flag.StringVar(&datasource, "datasource", "drone.sqlite", "")
|
||||||
|
flag.StringVar(&sslcert, "sslcert", "", "")
|
||||||
|
flag.StringVar(&sslkey, "sslkey", "", "")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// validate the TLS arguments
|
||||||
|
checkTLSFlags()
|
||||||
|
|
||||||
// setup database and handlers
|
// setup database and handlers
|
||||||
setupDatabase()
|
setupDatabase()
|
||||||
setupStatic()
|
setupStatic()
|
||||||
setupHandlers()
|
setupHandlers()
|
||||||
|
|
||||||
// start the webserver on the default port.
|
// start webserver using HTTPS or HTTP
|
||||||
panic(http.ListenAndServe(port, nil))
|
if sslcert != "" && sslkey != "" {
|
||||||
|
panic(http.ListenAndServeTLS(port, sslcert, sslkey, nil))
|
||||||
|
} else {
|
||||||
|
panic(http.ListenAndServe(port, nil))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checking if the TLS flags where supplied correctly.
|
||||||
|
func checkTLSFlags() {
|
||||||
|
|
||||||
|
if sslcert != "" && sslkey == "" {
|
||||||
|
log.Fatal("invalid configuration: -sslkey unspecified, but -sslcert was specified.")
|
||||||
|
} else if sslcert == "" && sslkey != "" {
|
||||||
|
log.Fatal("invalid configuration: -sslcert unspecified, but -sslkey was specified.")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the database connection and register with the
|
// setup the database connection and register with the
|
||||||
|
|
Loading…
Reference in a new issue