aboutsummaryrefslogtreecommitdiff
path: root/pkg/service/git.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-06-23 17:04:27 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-06-23 17:04:27 +0200
commit72495f4538215051540eb05c14db0ed16142e06e (patch)
tree293f0f4a9ad4954b8a2390d392e0a4a3bc9a3569 /pkg/service/git.go
parent6b96b76d66a929a2b428505809fda23a19005c63 (diff)
downloadcerrado-72495f4538215051540eb05c14db0ed16142e06e.tar.gz
cerrado-72495f4538215051540eb05c14db0ed16142e06e.tar.bz2
cerrado-72495f4538215051540eb05c14db0ed16142e06e.zip
ref: Move binary handling up to the handler
Now it is up to the handler to decide whether it wants to render a file or not, git only returns the content.
Diffstat (limited to 'pkg/service/git.go')
-rw-r--r--pkg/service/git.go34
1 files changed, 26 insertions, 8 deletions
diff --git a/pkg/service/git.go b/pkg/service/git.go
index 654d6ac..8e25261 100644
--- a/pkg/service/git.go
+++ b/pkg/service/git.go
@@ -139,37 +139,55 @@ func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) {
return repo.Tree(path)
}
-func (g *GitService) GetFileContent(name, ref, path string) (string, error) {
+func (g *GitService) IsBinary(name, ref, path string) (bool, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return "", RepositoryNotFoundErr
+ return false, RepositoryNotFoundErr
}
repo, err := git.OpenRepository(r.Path)
if err != nil {
- return "", err
+ return false, err
}
err = repo.SetRef(ref)
if err != nil {
- return "", err
+ return false, err
+ }
+
+ return repo.IsBinary(path)
+}
+
+func (g *GitService) GetFileContent(name, ref, path string) ([]byte, error) {
+ r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
+
+ repo, err := git.OpenRepository(r.Path)
+ if err != nil {
+ return nil, err
+ }
+ err = repo.SetRef(ref)
+ if err != nil {
+ return nil, err
}
return repo.FileContent(path)
}
-func (g *GitService) GetAbout(name string) (string, error) {
+func (g *GitService) GetAbout(name string) ([]byte, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return "", RepositoryNotFoundErr
+ return nil, RepositoryNotFoundErr
}
repo, err := git.OpenRepository(r.Path)
if err != nil {
- return "", err
+ return nil, err
}
err = repo.SetRef("")
if err != nil {
- return "", err
+ return nil, err
}
return repo.FileContent(r.About)