mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-22 03:20:41 +08:00
feat: TLS support
This commit is contained in:
+21
-2
@@ -138,6 +138,9 @@ type cfg struct {
|
|||||||
webdav *webdav.Config
|
webdav *webdav.Config
|
||||||
address string
|
address string
|
||||||
port string
|
port string
|
||||||
|
tls bool
|
||||||
|
cert string
|
||||||
|
key string
|
||||||
auth map[string]string
|
auth map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +150,9 @@ func parseConfig() *cfg {
|
|||||||
data := struct {
|
data := struct {
|
||||||
Address string `json:"address" yaml:"address"`
|
Address string `json:"address" yaml:"address"`
|
||||||
Port string `json:"port" yaml:"port"`
|
Port string `json:"port" yaml:"port"`
|
||||||
|
Tls bool `json:"tls" yaml:"tls"`
|
||||||
|
Cert string `json:"cert" yaml:"cert"`
|
||||||
|
Key string `json:"key" yaml:"key"`
|
||||||
Scope string `json:"scope" yaml:"scope"`
|
Scope string `json:"scope" yaml:"scope"`
|
||||||
Modify bool `json:"modify" yaml:"modify"`
|
Modify bool `json:"modify" yaml:"modify"`
|
||||||
Rules []map[string]interface{} `json:"rules" yaml:"rules"`
|
Rules []map[string]interface{} `json:"rules" yaml:"rules"`
|
||||||
@@ -154,6 +160,9 @@ func parseConfig() *cfg {
|
|||||||
}{
|
}{
|
||||||
Address: "0.0.0.0",
|
Address: "0.0.0.0",
|
||||||
Port: "0",
|
Port: "0",
|
||||||
|
Tls: false,
|
||||||
|
Cert: "cert.pem",
|
||||||
|
Key: "key.pem",
|
||||||
Scope: "./",
|
Scope: "./",
|
||||||
Modify: true,
|
Modify: true,
|
||||||
}
|
}
|
||||||
@@ -172,6 +181,9 @@ func parseConfig() *cfg {
|
|||||||
config := &cfg{
|
config := &cfg{
|
||||||
address: data.Address,
|
address: data.Address,
|
||||||
port: data.Port,
|
port: data.Port,
|
||||||
|
tls: data.Tls,
|
||||||
|
cert: data.Cert,
|
||||||
|
key: data.Key,
|
||||||
auth: map[string]string{},
|
auth: map[string]string{},
|
||||||
webdav: &webdav.Config{
|
webdav: &webdav.Config{
|
||||||
User: &webdav.User{
|
User: &webdav.User{
|
||||||
@@ -251,7 +263,14 @@ func main() {
|
|||||||
fmt.Println("Listening on", listener.Addr().String())
|
fmt.Println("Listening on", listener.Addr().String())
|
||||||
|
|
||||||
// Starts the server.
|
// Starts the server.
|
||||||
if err := http.Serve(listener, handler); err != nil {
|
if cfg.tls {
|
||||||
log.Fatal(err)
|
if err := http.ServeTLS(listener, handler, cfg.cert, cfg.key); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := http.Serve(listener, handler); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user