Go语言中的Webdav服务器

huangapple go评论96阅读模式
英文:

Webdav Server in Go

问题

我想使用Go实现一个WebDAV服务器,并找到了一个新的"x"包,可以在这里找到:

但是我不知道如何使用这个包来完成它。有人可以帮我解决这个问题吗?

我尝试了以下代码:

func main(){
    fs := new(webdav.FileSystem)
    ls := new(webdav.LockSystem)
    h := new(webdav.Handler)
    h.FileSystem = *fs
    h.LockSystem = *ls
    //然后将Handler.ServeHTTP方法用作http.HandleFunc
    http.HandleFunc("/", h.ServeHTTP)
    http.ListenAndServe(":5555", nil)
}

如果我尝试连接到服务器,我会得到一个内部服务器错误。

我做错了什么?

谢谢你的帮助。

英文:

I want to implement a webdav-server with Go and found a new "x" package <a href="http://www.golang.org/x/net/webdav">here:</a>

But I don't know how to use this package to get it done.
Can someone help me with this issue?

I tried this:

func main(){
    fs := new(webdav.FileSystem)
    ls := new(webdav.LockSystem)
    h := new(webdav.Handler)
    h.FileSystem = *fs
    h.LockSystem = *ls
    //then use the Handler.ServeHTTP Method as the http.HandleFunc
    http.HandleFunc(&quot;/&quot;, h.ServeHTTP)
    http.ListenAndServe(&quot;:5555&quot;, nil)
}

If I try to connect to the server, I get an internal server error.

What am I doing wrong?

Thanks for your help.

答案1

得分: 3

x/net/webdav仍处于开发的早期阶段。许多关键部分仍在实现中,目前还不能直接使用。查看源代码后发现,超过一半所需的结构和函数仍然完全缺失。

不幸的是,目前没有基于Go的WebDAV服务器实现。(如果有人能纠正我,请随时这样做!)

英文:

The x/net/webdav is still in early phase of development. Many critical parts are still being implemented, and it can not be used as such at this moment. Taking a look at the source code over half of the necessary structures and functions are still completely missing.

Unfortunately there are no Go based webdav server implementations at this moment. (In case someone can correct me, please feel free to do so!)

答案2

得分: 0

func main() {
fs := new(webdav.FileSystem)
ls := new(webdav.LockSystem)
h := new(webdav.Handler)
h.FileSystem = fs
h.LockSystem = ls
//然后将Handler.ServeHTTP方法用作http.HandleFunc
http.HandleFunc("/", h.ServeHTTP)
http.ListenAndServe(":5555", nil)
}

尝试移除"fs"和"ls"之前的*,因为它们已经是指针。
注意:如果你需要分配指针,请使用&而不是*。

英文:
func main(){
    fs := new(webdav.FileSystem)
    ls := new(webdav.LockSystem)
    h := new(webdav.Handler)
    h.FileSystem = fs
    h.LockSystem = ls
    //then use the Handler.ServeHTTP Method as the http.HandleFunc
    http.HandleFunc(&quot;/&quot;, h.ServeHTTP)
    http.ListenAndServe(&quot;:5555&quot;, nil)
}

try to remove the * before "fs" and "ls" because they are already pointers.
NB : if you have to assign pointer use & and not *

答案3

得分: 0

http://localhost:8080/上创建一个WebDAV服务器,将文件夹C:\myfiles挂载上去。

package main

import (
	"net/http"

	"golang.org/x/net/webdav"
)

func main() {
	handler := &webdav.Handler{
		FileSystem: webdav.Dir(`C:\myfiles`),
		LockSystem: webdav.NewMemLS(),
	}

	http.ListenAndServe("localhost:8080", handler)
}

在Windows上将其挂载到E盘:

net use e: http://localhost:8080/

在资源管理器中打开挂载的驱动器:

explorer.exe e:
英文:

Create a webdav server on http://localhost:8080/ which mounts the folder C:\myfiles.

package main

import (
	&quot;net/http&quot;

	&quot;golang.org/x/net/webdav&quot;
)

func main() {
	handler := &amp;webdav.Handler{
		FileSystem: webdav.Dir(`C:\myfiles`),
		LockSystem: webdav.NewMemLS(),
	}

	http.ListenAndServe(&quot;localhost:8080&quot;, handler)
}

Mount to Letter E: in windows:

net use e: http://localhost:8080/

Open mounted drive in explorer

explorer.exe e:

huangapple
  • 本文由 发表于 2014年12月4日 01:59:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/27278501.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定