wocao
This commit is contained in:
+21
-31
@@ -9,17 +9,25 @@ import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
type Config struct {
|
||||
Root string
|
||||
RPCAddr string
|
||||
SSHAddr string
|
||||
ManageAddr string
|
||||
AuthURL string
|
||||
Root string
|
||||
// SSHAddr: git SSH listen (clone/push over SSH, keyed auth).
|
||||
SSHAddr string
|
||||
// HTTPAddr: plain HTTP listen for git smart-HTTP clone/push
|
||||
// (/:owner/:name.git/*) + the index page. This is the user-facing git
|
||||
// transport (nginx routes .git/* here). Empty = no HTTP listener.
|
||||
HTTPAddr string
|
||||
// GitRPCAddrs: Connect-RPC listen addresses (GitService + ManageService)
|
||||
// PLUS the binary /raw, /archive, /patch content endpoints. Others dial
|
||||
// these to read/write/modify repo content and drive repo lifecycle. May be
|
||||
// multiple (e.g. a unix socket for a local TUI and a tcp addr for the
|
||||
// console). Empty = no gitrpc listener.
|
||||
GitRPCAddrs []string
|
||||
// HookScript is an operator-provided executable invoked by every Git hook.
|
||||
// The hook name is its first argument; Git's original args, stdin and
|
||||
// environment are preserved. Empty disables hook effects.
|
||||
HookScript string
|
||||
DBUri string
|
||||
SkipAuth bool
|
||||
|
||||
preparedDbUri string
|
||||
prepared atomic.Bool
|
||||
@@ -31,20 +39,10 @@ func (c *Config) RepoRoot() string {
|
||||
return filepath.Join(c.Root, "repos")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (c *Config) TemplateDir() string {
|
||||
return filepath.Join(c.Root, "template")
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (c *Config) HookSock() string {
|
||||
return filepath.Join(c.Root, "hook.sock")
|
||||
}
|
||||
|
||||
|
||||
func (c *Config) Prepare() error {
|
||||
if c.prepared.Load() {
|
||||
return nil
|
||||
@@ -60,12 +58,10 @@ func (c *Config) Prepare() error {
|
||||
if err != nil {
|
||||
return errors.New("simplegit: ParseDBURI failed")
|
||||
}
|
||||
if c.RPCAddr == "" {
|
||||
return errors.New("simplegit: -rpc is required (the HTTP server is this binary's only listener)")
|
||||
}
|
||||
if c.ManageAddr == "" {
|
||||
return fmt.Errorf("*manageAddr == nil")
|
||||
}
|
||||
// Listeners are all optional: a daemon with only -ssh, only -http, only
|
||||
// -gitrpc, or any combination is valid (empty = that surface is disabled).
|
||||
// At least one of -http/-ssh/-gitrpc should be set for the daemon to do
|
||||
// anything useful, but that is the operator's choice, not a hard error.
|
||||
c.prepared.Store(true)
|
||||
return nil
|
||||
}
|
||||
@@ -91,20 +87,14 @@ func (c *Config) DBURI() string {
|
||||
return c.preparedDbUri
|
||||
}
|
||||
|
||||
|
||||
|
||||
func normalizeName(name string) string {
|
||||
return strings.TrimSuffix(name, ".git")
|
||||
}
|
||||
|
||||
|
||||
func relPath(owner, name string) string {
|
||||
return owner + "/" + normalizeName(name) + ".git"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (s *Config) RepoPath(owner, name string) (string, error) {
|
||||
name = normalizeName(name)
|
||||
rel := relPath(owner, name)
|
||||
|
||||
Reference in New Issue
Block a user