aboutsummaryrefslogtreecommitdiff
path: root/webdav.go
blob: 8f55b4426a0ec2f484d338c154aeb6d2fd5a5a9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"github.com/minio/minio-go/v7"
	"git.deuxfleurs.fr/Deuxfleurs/bagage/s3"
	"golang.org/x/net/webdav"
	"log"
	"net/http"
)

type WebDav struct {
	WithConfig *Config
}

func (wd WebDav) WithMC(mc *minio.Client) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		(&webdav.Handler{
			Prefix:     wd.WithConfig.DavPath,
			FileSystem: s3.NewS3FS(mc),
			LockSystem: webdav.NewMemLS(),
			Logger: func(r *http.Request, err error) {
				log.Printf("INFO: %s %s %s\n", r.RemoteAddr, r.Method, r.URL)
				if err != nil {
					log.Printf("ERR: %v", err)
				}
			},
		}).ServeHTTP(w, r)
	})
}