aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/config/config.go12
-rw-r--r--pkg/ext/compression.go6
-rw-r--r--pkg/ext/router.go2
-rw-r--r--pkg/service/git.go27
-rw-r--r--pkg/worker/http.go4
5 files changed, 28 insertions, 23 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 3759b7c..fd19808 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -14,9 +14,9 @@ import (
)
var (
- ScanPathErr = errors.New("Scan path does not exist")
- RepoPathErr = errors.New("Repository path does not exist")
- InvalidPropertyErr = errors.New("Invalid property")
+ ErrScanPath = errors.New("Scan path does not exist")
+ ErrRepoPath = errors.New("Repository path does not exist")
+ ErrInvalidProperty = errors.New("Invalid property")
)
type (
@@ -113,7 +113,7 @@ func (c *ConfigurationRepository) List() []*GitRepositoryConfiguration {
// and applying them default configuration.
func (c *ConfigurationRepository) expandOnScanPath(scanPath string, public bool) error {
if !u.FileExist(scanPath) {
- return ScanPathErr
+ return ErrScanPath
}
entries, err := os.ReadDir(scanPath)
@@ -185,7 +185,7 @@ func setRepositories(block scfg.Block, repositories *[]*GitRepositoryConfigurati
if len(r.Params) != 1 {
return fmt.Errorf(
"Invlid number of params for repository: %w",
- InvalidPropertyErr,
+ ErrInvalidProperty,
)
}
@@ -198,7 +198,7 @@ func setRepositories(block scfg.Block, repositories *[]*GitRepositoryConfigurati
return fmt.Errorf(
"Invlid number of params for %s: %w",
d.Name,
- InvalidPropertyErr,
+ ErrInvalidProperty,
)
}
diff --git a/pkg/ext/compression.go b/pkg/ext/compression.go
index 9e933ef..6c7a219 100644
--- a/pkg/ext/compression.go
+++ b/pkg/ext/compression.go
@@ -16,7 +16,7 @@ import (
)
var (
- invalidParamErr = errors.New("Invalid weighted param")
+ errInvalidParam = errors.New("Invalid weighted param")
)
type CompressionResponseWriter struct {
@@ -135,7 +135,7 @@ func GetLZWWriter(w io.Writer) io.WriteCloser {
func getWeighedValue(part string) (float64, error) {
ps := strings.SplitN(part, "=", 2)
if len(ps) != 2 {
- return 0, invalidParamErr
+ return 0, errInvalidParam
}
if name := strings.TrimSpace(ps[0]); name == "q" {
w, err := strconv.ParseFloat(ps[1], 64)
@@ -145,5 +145,5 @@ func getWeighedValue(part string) (float64, error) {
return w, nil
}
- return 0, invalidParamErr
+ return 0, errInvalidParam
}
diff --git a/pkg/ext/router.go b/pkg/ext/router.go
index 5d22814..96da1c9 100644
--- a/pkg/ext/router.go
+++ b/pkg/ext/router.go
@@ -34,7 +34,7 @@ func (r *Router) AddMiddleware(middleware Middleware) {
func wrapError(next ErrorRequestHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := next(w, r); err != nil {
- if errors.Is(err, service.RepositoryNotFoundErr) {
+ if errors.Is(err, service.ErrRepositoryNotFound) {
NotFound(w)
} else {
InternalServerError(w, err)
diff --git a/pkg/service/git.go b/pkg/service/git.go
index 8e25261..1d21204 100644
--- a/pkg/service/git.go
+++ b/pkg/service/git.go
@@ -31,7 +31,7 @@ type (
)
var (
- RepositoryNotFoundErr = errors.New("Repository not found")
+ ErrRepositoryNotFound = errors.New("Repository not found")
)
// TODO: make it configurable
@@ -79,7 +79,7 @@ func (g *GitService) ListRepositories() ([]*Repository, error) {
func (g *GitService) ListCommits(name, ref string, count int) ([]*object.Commit, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -97,7 +97,7 @@ func (g *GitService) ListCommits(name, ref string, count int) ([]*object.Commit,
func (g *GitService) WriteTarGZip(w io.Writer, name, ref string, prefix string) error {
r := g.configRepo.GetByName(name)
if r == nil {
- return RepositoryNotFoundErr
+ return ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -124,7 +124,7 @@ func (g *GitService) WriteTarGZip(w io.Writer, name, ref string, prefix string)
func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -142,7 +142,7 @@ func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) {
func (g *GitService) IsBinary(name, ref, path string) (bool, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return false, RepositoryNotFoundErr
+ return false, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -160,7 +160,7 @@ func (g *GitService) IsBinary(name, ref, path string) (bool, error) {
func (g *GitService) GetFileContent(name, ref, path string) ([]byte, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -178,7 +178,7 @@ func (g *GitService) GetFileContent(name, ref, path string) ([]byte, error) {
func (g *GitService) GetAbout(name string) ([]byte, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -190,13 +190,18 @@ func (g *GitService) GetAbout(name string) ([]byte, error) {
return nil, err
}
- return repo.FileContent(r.About)
+ file, err := repo.FileContent(r.About)
+ if err != nil {
+ return nil, err
+ }
+
+ return file, nil
}
func (g *GitService) ListTags(name string) ([]*plumbing.Reference, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -209,7 +214,7 @@ func (g *GitService) ListTags(name string) ([]*plumbing.Reference, error) {
func (g *GitService) ListBranches(name string) ([]*plumbing.Reference, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
@@ -222,7 +227,7 @@ func (g *GitService) ListBranches(name string) ([]*plumbing.Reference, error) {
func (g *GitService) GetHead(name string) (*plumbing.Reference, error) {
r := g.configRepo.GetByName(name)
if r == nil {
- return nil, RepositoryNotFoundErr
+ return nil, ErrRepositoryNotFound
}
repo, err := git.OpenRepository(r.Path)
diff --git a/pkg/worker/http.go b/pkg/worker/http.go
index 1559ba2..55defd7 100644
--- a/pkg/worker/http.go
+++ b/pkg/worker/http.go
@@ -10,7 +10,7 @@ import (
)
var (
- UnsupportedSchemeErr = errors.New("Ivalid schema, only tcp and unix supported")
+ ErrUnsupportedScheme = errors.New("Ivalid schema, only tcp and unix supported")
)
type ServerTask struct {
@@ -72,6 +72,6 @@ func getListen(addr string) (net.Listener, error) {
}
return net.Listen(u.Scheme, host)
default:
- return nil, UnsupportedSchemeErr
+ return nil, ErrUnsupportedScheme
}
}