dave/cmd/server/main.go

39 lines
953 B
Go
Raw Normal View History

package main
import (
2018-04-09 14:12:54 +02:00
"fmt"
"github.com/abbot/go-http-auth"
2018-04-09 15:27:21 +02:00
"github.com/micromata/swd/app"
"golang.org/x/net/webdav"
"log"
2018-04-09 15:27:21 +02:00
"net/http"
)
func main() {
2018-04-09 14:12:54 +02:00
config := app.ParseConfig()
wdHandler := &webdav.Handler{
Prefix: config.Prefix,
FileSystem: webdav.Dir(config.Dir),
LockSystem: webdav.NewMemLS(),
}
a := &app.App{
Config: config,
Handler: wdHandler,
}
authenticator := auth.NewBasicAuthenticator(config.Address, app.Authorize(config))
http.Handle("/", app.AuthenticatedHandler(authenticator, app.AuthWebdavHandlerFunc(app.Handle), a))
2018-04-09 14:12:54 +02:00
connAddr := fmt.Sprintf("%s:%s", config.Address, config.Port)
if config.TLS != nil {
fmt.Printf("TLS Server is starting and listening at: %s\n", connAddr)
log.Fatal(http.ListenAndServeTLS(connAddr, config.TLS.CertFile, config.TLS.KeyFile, nil))
} else {
fmt.Printf("Server is starting and listening at: %s\n", connAddr)
log.Fatal(http.ListenAndServe(connAddr, nil))
}
}