2018-04-09 13:02:14 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-09 14:12:54 +02:00
|
|
|
"fmt"
|
2018-04-09 15:27:21 +02:00
|
|
|
"github.com/micromata/swd/app"
|
2018-04-14 20:49:39 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-04-09 15:27:21 +02:00
|
|
|
"golang.org/x/net/webdav"
|
|
|
|
"net/http"
|
2018-04-09 13:02:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-04-14 20:49:39 +02:00
|
|
|
log.SetFormatter(&log.TextFormatter{})
|
|
|
|
|
2018-04-09 14:12:54 +02:00
|
|
|
config := app.ParseConfig()
|
|
|
|
|
2018-04-09 13:02:14 +02:00
|
|
|
wdHandler := &webdav.Handler{
|
2018-04-10 22:02:48 +02:00
|
|
|
Prefix: config.Prefix,
|
2018-04-11 16:19:00 +02:00
|
|
|
FileSystem: &app.Dir{
|
|
|
|
Config: config,
|
2018-04-10 22:02:48 +02:00
|
|
|
},
|
2018-04-09 13:02:14 +02:00
|
|
|
LockSystem: webdav.NewMemLS(),
|
2018-04-18 15:46:06 +02:00
|
|
|
Logger: func(request *http.Request, err error) {
|
2018-04-21 21:18:54 +02:00
|
|
|
if config.Log.Error && err != nil {
|
2018-04-18 15:46:06 +02:00
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
},
|
2018-04-09 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 15:20:23 +02:00
|
|
|
a := &app.App{
|
|
|
|
Config: config,
|
|
|
|
Handler: wdHandler,
|
|
|
|
}
|
|
|
|
|
2018-04-10 22:02:48 +02:00
|
|
|
http.Handle("/", app.NewBasicAuthWebdavHandler(a))
|
2018-04-10 15:20:23 +02:00
|
|
|
|
2018-04-09 14:12:54 +02:00
|
|
|
connAddr := fmt.Sprintf("%s:%s", config.Address, config.Port)
|
2018-04-09 15:24:57 +02:00
|
|
|
|
|
|
|
if config.TLS != nil {
|
2018-04-14 20:49:39 +02:00
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"address": config.Address,
|
|
|
|
"port": config.Port,
|
|
|
|
"security": "TLS",
|
|
|
|
}).Info("Server is starting and listening")
|
2018-04-10 15:20:23 +02:00
|
|
|
log.Fatal(http.ListenAndServeTLS(connAddr, config.TLS.CertFile, config.TLS.KeyFile, nil))
|
2018-04-09 15:24:57 +02:00
|
|
|
} else {
|
2018-04-14 20:49:39 +02:00
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"address": config.Address,
|
|
|
|
"port": config.Port,
|
|
|
|
"security": "none",
|
|
|
|
}).Info("Server is starting and listening")
|
2018-04-10 15:20:23 +02:00
|
|
|
log.Fatal(http.ListenAndServe(connAddr, nil))
|
2018-04-09 15:24:57 +02:00
|
|
|
}
|
2018-04-09 13:02:14 +02:00
|
|
|
}
|