summaryrefslogtreecommitdiffstats
path: root/module.go
diff options
context:
space:
mode:
authorTEC <git@tecosaur.net>2024-01-07 23:29:00 +0800
committerTEC <git@tecosaur.net>2024-01-08 00:29:18 +0800
commit41e72838399ae8ac99497c51a87765dd0a7697a8 (patch)
tree2f1634b1fb653a8ca63ab519234bb7615efe1718 /module.go
downloadcaddy-fs-git-41e72838399ae8ac99497c51a87765dd0a7697a8.tar.zst
Starting point
Diffstat (limited to 'module.go')
-rw-r--r--module.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/module.go b/module.go
new file mode 100644
index 0000000..7b9fc56
--- /dev/null
+++ b/module.go
@@ -0,0 +1,56 @@
+package caddyfsgit
+
+import (
+ "errors"
+ "io"
+ "io/fs"
+ "path"
+ "strings"
+ "time"
+
+ "github.com/go-git/go-git/v5"
+ "github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/filemode"
+ "github.com/go-git/go-git/v5/plumbing/object"
+)
+
+func init() {
+ caddy.RegisterModule(FS{})
+}
+
+// Interface guards
+var (
+ _ fs.ReadDirFS = (*FS)(nil)
+ _ caddyfile.Unmarshaler = (*FS)(nil)
+)
+
+// FS provides a view into a specific git tree.
+type FS struct {
+ fs.ReadDirFS `json:"-"`
+ repoPath string `json:"path,omitempty"`
+ revision string `json:"revision,omitempty"`
+ repo *git.Repository
+ logger *zap.Logger
+}
+
+// CaddyModule returns the Caddy module information.
+func (FS) CaddyModule() caddy.ModuleInfo {
+ return caddy.ModuleInfo{
+ ID: "caddy.fs.git",
+ New: func() caddy.Module { return new(FS) },
+ }
+}
+
+func (fs *FS) Provision(ctx caddy.Context) error {
+ repo, err := git.PlainOpen(fs.repoPath)
+ if err != nil {
+ return fmt.Errorf("failed to open git repository: %w", err)
+ }
+ // TODO
+ return nil
+}
+
+func (fs *FS) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
+ // TODO
+ return nil
+}