46 lines
1009 B
Go
46 lines
1009 B
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"gitocean/internal/gitutil"
|
|
"gitocean/internal/httputil"
|
|
"gitocean/internal/validate"
|
|
)
|
|
|
|
// ---------------- Shared helpers ----------------
|
|
|
|
func decodeJSON(w http.ResponseWriter, r *http.Request, out any) bool {
|
|
return httputil.DecodeJSON(w, r, out)
|
|
}
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
|
httputil.WriteJSON(w, status, v)
|
|
}
|
|
|
|
func writeError(w http.ResponseWriter, status int, msg string) {
|
|
httputil.WriteError(w, status, msg)
|
|
}
|
|
|
|
func isReservedName(s string) bool {
|
|
return validate.ReservedName(s)
|
|
}
|
|
|
|
func (s *Server) repoPath(owner, name string) string {
|
|
return filepath.Join(s.storage, "repos", strings.ToLower(owner), strings.ToLower(name)+".git")
|
|
}
|
|
|
|
func gitInitBare(path string) error {
|
|
return gitutil.InitBare(path)
|
|
}
|
|
|
|
func gitBranchExists(repoPath, branch string) bool {
|
|
return gitutil.BranchExists(repoPath, branch)
|
|
}
|
|
|
|
func runGit(dir string, args ...string) error {
|
|
return gitutil.Run(dir, args...)
|
|
}
|