local-server/cmd/dkl-local-server/main.go

57 lines
1.1 KiB
Go
Raw Normal View History

2018-06-12 10:09:47 +00:00
package main
import (
"flag"
"log"
"net/http"
"path/filepath"
2019-02-01 07:28:08 +00:00
restful "github.com/emicklei/go-restful"
2019-02-04 02:56:43 +00:00
"github.com/mcluseau/go-swagger-ui"
2018-06-12 10:09:47 +00:00
"novit.nc/direktil/pkg/cas"
2019-02-01 07:28:08 +00:00
"novit.nc/direktil/local-server/pkg/apiutils"
2018-06-12 10:09:47 +00:00
)
const (
etcDir = "/etc/direktil"
)
var (
address = flag.String("address", ":7606", "HTTP listen address")
tlsAddress = flag.String("tls-address", "", "HTTPS listen address")
certFile = flag.String("tls-cert", etcDir+"/server.crt", "Server TLS certificate")
keyFile = flag.String("tls-key", etcDir+"/server.key", "Server TLS key")
casStore cas.Store
)
func main() {
flag.Parse()
if *address == "" && *tlsAddress == "" {
log.Fatal("no listen address given")
}
casStore = cas.NewDir(filepath.Join(*dataDir, "cache"))
go casCleaner()
2019-02-01 07:28:08 +00:00
apiutils.Setup(func() {
2019-04-15 17:56:31 +00:00
registerWS(restful.DefaultContainer)
2019-02-01 07:28:08 +00:00
})
2019-02-04 02:56:43 +00:00
swaggerui.HandleAt("/swagger-ui/")
2018-07-07 01:22:35 +00:00
2018-06-12 10:09:47 +00:00
if *address != "" {
log.Print("HTTP listening on ", *address)
go log.Fatal(http.ListenAndServe(*address, nil))
}
if *tlsAddress != "" {
log.Print("HTTPS listening on ", *tlsAddress)
go log.Fatal(http.ListenAndServeTLS(*tlsAddress, *certFile, *keyFile, nil))
}
select {}
}