diff --git a/Dockerfile b/Dockerfile index 895a261..7470f5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,17 @@ -FROM golang:1 AS build +FROM golang:1-alpine AS build WORKDIR /src COPY go.* ./ +RUN go mod download -x COPY pkg ./pkg/ COPY cmd ./cmd/ -RUN go get ./... RUN CGO_ENABLED=0 GOOS=linux go install ./... FROM alpine AS runtime WORKDIR /target +COPY web web COPY --from=build /go/bin/ . FROM scratch COPY --from=runtime /target / +WORKDIR /web ENTRYPOINT ["/webfs"] diff --git a/cmd/webfs/main.go b/cmd/webfs/main.go index 8be3a0f..fa0717f 100644 --- a/cmd/webfs/main.go +++ b/cmd/webfs/main.go @@ -5,14 +5,31 @@ import ( "golang.org/x/net/webdav" "log" "net/http" + "strings" ) +type Handler struct { + webdav.Handler +} + +func (h *Handler)ServeHTTP(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case "GET", "HEAD": + if strings.HasSuffix(r.URL.Path, "/") { + r.URL.Path += "index.html" + } + } + h.Handler.ServeHTTP(w, r) +} + + func main() { - address := flag.String("a", "localhost:8080", "Address to listen to.") + address := flag.String("a", ":8080", "Address to listen to") + directory := flag.String("d", ".", "Directory to serve") flag.Parse() - handler := &webdav.Handler{} - handler.FileSystem = webdav.Dir(".") + handler := &Handler{} + handler.FileSystem = webdav.Dir(*directory) handler.LockSystem = webdav.NewMemLS() log.Println("Listening on", *address) diff --git a/go.mod b/go.mod index d39c0b4..5034048 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module woozle.org/neale/webfs go 1.15 -require ( - github.com/bakape/thumbnailer v1.0.0 - golang.org/x/net v0.6.0 -) +require golang.org/x/net v0.7.0 diff --git a/go.sum b/go.sum index f87b4ff..4b6f231 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/bakape/thumbnailer v1.0.0 h1:fmaLCJ6sJ5wCAUmB3hhzgFAZ5G3cpueo3olI9N0ox3E= -github.com/bakape/thumbnailer v1.0.0/go.mod h1:PVB2nXXJHD4KAUWn9HaNKtWeDeAb9BFQ7oDOAdZCKUM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -7,8 +5,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..9cb7466 --- /dev/null +++ b/web/index.html @@ -0,0 +1,6 @@ + + + webfs success +

It Worked!

+

It's running. Now you need to mount something in /web

+