Documentation
¶
Overview ¶
Package git provides a source.Reader implementation that reads scripts from a git repository. It clones the repo to a local temp directory and reads files from the working tree. Hot-reload is supported by polling for new commits (git pull + HEAD hash comparison).
Construction:
src, err := git.New(ctx,
git.WithRepoURL("https://github.com/user/scripts.git"),
git.WithBranch("main"),
git.WithPrefix("scripts/lua/"),
)
Hot-reload uses commit-hash polling: the Watcher periodically runs git pull and compares the HEAD hash with the one recorded at the last Load.
Index ¶
- Variables
- func IsNotFound(err error) bool
- type Option
- func WithAuth(username, password string) Option
- func WithBranch(branch string) Option
- func WithDepth(depth int) Option
- func WithLocalPath(path string) Option
- func WithPrefix(prefix string) Option
- func WithPullInterval(d time.Duration) Option
- func WithRepoURL(url string) Option
- func WithSSHKey(keyPath string) Option
- func WithToken(token string) Option
- type Reader
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("git source: key not found")
ErrNotFound is returned (wrapped) by Load when the requested key does not exist in the git repository. Detect with errors.Is(err, ErrNotFound) or the convenience helper IsNotFound.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err represents a "file not found" error.
Types ¶
type Option ¶
type Option func(*configOptions)
Option configures a Reader. Pass to New.
func WithBranch ¶
WithBranch sets the branch, tag, or ref to checkout (default "HEAD").
func WithLocalPath ¶
WithLocalPath sets a local repository path. When set, the Reader will open the local repo directly instead of cloning from a remote URL. This is useful for development / testing.
func WithPrefix ¶
WithPrefix sets a path prefix that is transparently prepended to every key. Leading slashes are stripped.
WithPrefix("scripts/lua/") + key "main.lua" -> "scripts/lua/main.lua"
func WithPullInterval ¶
WithPullInterval sets the polling interval for Watch (default 30s).
func WithRepoURL ¶
WithRepoURL sets the remote git repository URL to clone from.
WithRepoURL("https://github.com/user/scripts.git")
WithRepoURL("git@github.com:user/scripts.git")
func WithSSHKey ¶
WithSSHKey sets the path to an SSH private key for authentication.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads scripts from a git repository.
All exported methods are safe for concurrent use. Reader implements the source.ReadWatcher interface.
func New ¶
New creates a git-backed Reader.
At minimum, either WithRepoURL or WithLocalPath must be supplied. When WithRepoURL is used, the repo is cloned to a temporary directory. When WithLocalPath is used, the repo is opened directly from the local filesystem (no clone).
func (*Reader) Close ¶
Close releases resources. If the Reader cloned the repo to a temp directory, the directory is removed.
func (*Reader) Load ¶
Load reads the file at the given key from the git working tree. Context cancellation propagates to the underlying read.
An absent file is reported as a wrapped ErrNotFound.
func (*Reader) Watch ¶
Watch returns a channel that signals when the git repository receives new commits that may affect the file identified by `key`.
It works by periodically running `git pull` and comparing the HEAD commit hash with the one recorded at the last Load. If the hash has changed, a signal is sent on the channel.
The returned channel is closed when the context is cancelled. Callers should re-Load the script after receiving from the channel.