summaryrefslogtreecommitdiffstats
path: root/module.go
blob: 7b9fc566ad3390801eb1430d4f88df13f5623838 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
}