Add Caddyfile support to zipfile plugin
This commit is contained in:
parent
97af6b6073
commit
62bb70b20a
2 changed files with 22 additions and 18 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"archive/zip"
|
||||
"fmt"
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
"go4.org/readerutil"
|
||||
"io"
|
||||
"io/fs"
|
||||
|
@ -37,7 +38,10 @@ func (z *ZipFs) Provision(caddy.Context) (err error) {
|
|||
}
|
||||
|
||||
func (z *ZipFs) Cleanup() error {
|
||||
return z.reader.Close()
|
||||
if z.reader != nil {
|
||||
return z.reader.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileWrapper struct {
|
||||
|
@ -62,3 +66,20 @@ func (z *ZipFs) Open(name string) (fs.File, error) {
|
|||
File: f,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UnmarshalCaddyfile unmarshals a zipfile instantiation from a Caddyfile.
|
||||
//
|
||||
// Example syntax:
|
||||
//
|
||||
// filesystem zf zipfile /path/to/my/website.zip
|
||||
func (z *ZipFs) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
d.Next()
|
||||
var arg string
|
||||
if !d.Args(&arg) {
|
||||
return d.Err("missing ZIP file path")
|
||||
}
|
||||
|
||||
z.SourceZipPath = arg
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package httpsrv
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewSitesServer(args ServerArgs) *http.Server {
|
||||
return newServer(args, args.Config.HTTP.SitesAddress, handleErrors(args.Logger, func(rw http.ResponseWriter, rq *http.Request) error {
|
||||
h, err := args.Core.RouteRequest(rq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("handle sites request: %w", err)
|
||||
}
|
||||
h.ServeHTTP(rw, rq)
|
||||
return nil
|
||||
}))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue