فهرست منبع

[dav] GinFS draft (so far mainly sigs)

cgars 7 سال پیش
والد
کامیت
c7edcae509
2فایلهای تغییر یافته به همراه30 افزوده شده و 2 حذف شده
  1. 1 1
      cmd/web.go
  2. 29 1
      pkg/dav/dav.go

+ 1 - 1
cmd/web.go

@@ -158,7 +158,7 @@ func newMacaron() *macaron.Macaron {
 	}))
 	m.Use(context.Contexter())
 	// Webdav handler todo: implement
-	h := &webdav.Handler{}
+	h := &webdav.Handler{FileSystem:&dav.GinFS{}, LockSystem:webdav.NewMemLS()}
 	m.Map(h)
 	return m
 }

+ 29 - 1
pkg/dav/dav.go

@@ -3,10 +3,38 @@ package dav
 import (
 	"github.com/G-Node/gogs/pkg/context"
 	"golang.org/x/net/webdav"
+	"os"
+	"fmt"
 )
 
 func Dav(c *context.Context, handler *webdav.Handler) {
-	
+	handler.ServeHTTP(c.Resp, c.Req.Request)
 	c.Write([]byte("Hallo"))
 	return
 }
+
+// GinFS implements webdav (it implements webdav.Habdler) read only access to a repository
+type GinFS struct{}
+
+// Just return an error. -> Read Only
+func (fs *GinFS) Mkdir(name string, perm os.FileMode) error {
+	return fmt.Errorf("Mkdir not implemented for read only gin FS")
+}
+
+// Just return an error. -> Read Only
+func (fs *GinFS) RemoveAll(name string) error {
+	return fmt.Errorf("Remove not implemented for read only gin FS")
+}
+
+// Just return an error. -> Read Only
+func (fs *GinFS) Rename(oldName, newName string) error {
+	return fmt.Errorf("Rename not implemented for read only gin FS")
+}
+
+func (fs *GinFS) OpenFile(name string, flag int, perm os.FileMode) (webdav.File, error) {
+	return nil, nil
+}
+
+func (fs *GinFS) Stat(name string) (os.FileInfo, error) {
+	return nil, nil
+}