internal: fix linter errors

Fix errors reported by default golangci-lint linters
This commit is contained in:
Simone Gotti 2019-07-02 16:20:53 +02:00
parent 8ef3c1d9b3
commit 3a7ba2694d
9 changed files with 18 additions and 19 deletions

View File

@ -280,9 +280,9 @@ func (s *Steps) UnmarshalJSON(b []byte) error {
case "run": case "run":
var s RunStep var s RunStep
switch stepSpec.(type) { switch stepSpec := stepSpec.(type) {
case string: case string:
s.Command = stepSpec.(string) s.Command = stepSpec
default: default:
if err := json.Unmarshal(stepSpecRaw, &s); err != nil { if err := json.Unmarshal(stepSpecRaw, &s); err != nil {
return err return err

View File

@ -177,12 +177,12 @@ func (db *DB) Do(f func(tx *Tx) error) error {
} }
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
tx.Rollback() _ = tx.Rollback()
panic(p) panic(p)
} }
}() }()
if err = f(tx); err != nil { if err = f(tx); err != nil {
tx.Rollback() _ = tx.Rollback()
return err return err
} }
return tx.Commit() return tx.Commit()

View File

@ -159,6 +159,11 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
repoPath, reqType, err := MatchPath(r.URL.Path) repoPath, reqType, err := MatchPath(r.URL.Path)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
repoAbsPath, exists, err := h.repoAbsPathFunc(h.reposDir, repoPath) repoAbsPath, exists, err := h.repoAbsPathFunc(h.reposDir, repoPath)
if err != nil { if err != nil {
if err == ErrWrongRepoPath { if err == ErrWrongRepoPath {
@ -207,7 +212,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
w.Header().Set("Content-Type", "application/x-git-"+serviceName+"-advertisement") w.Header().Set("Content-Type", "application/x-git-"+serviceName+"-advertisement")
w.Write(res) _, _ = w.Write(res)
case RequestTypeUploadPack: case RequestTypeUploadPack:
w.Header().Set("Content-Type", "application/x-git-upload-pack-result") w.Header().Set("Content-Type", "application/x-git-upload-pack-result")

View File

@ -171,7 +171,6 @@ func unescape(s string) (string, bool, error) {
if nc > splitLength && nc%splitLength == 2 && s[len(s)-2:] == ".f" { if nc > splitLength && nc%splitLength == 2 && s[len(s)-2:] == ".f" {
hasFileMarker = true hasFileMarker = true
s = s[:len(s)-2] s = s[:len(s)-2]
nc -= 2
} }
if n == 0 && ns == 0 { if n == 0 && ns == 0 {

View File

@ -104,8 +104,8 @@ func (p *Process) Kill() {
if p.Cmd == nil { if p.Cmd == nil {
panic(fmt.Errorf("p: %s, cmd is empty", p.uid)) panic(fmt.Errorf("p: %s, cmd is empty", p.uid))
} }
p.Cmd.Cmd.Process.Signal(os.Kill) _ = p.Cmd.Cmd.Process.Signal(os.Kill)
p.Cmd.Wait() _ = p.Cmd.Wait()
p.Cmd = nil p.Cmd = nil
} }
@ -115,8 +115,8 @@ func (p *Process) Stop() {
panic(fmt.Errorf("p: %s, cmd is empty", p.uid)) panic(fmt.Errorf("p: %s, cmd is empty", p.uid))
} }
p.Cmd.Continue() p.Cmd.Continue()
p.Cmd.Cmd.Process.Signal(os.Interrupt) _ = p.Cmd.Cmd.Process.Signal(os.Interrupt)
p.Cmd.Wait() _ = p.Cmd.Wait()
p.Cmd = nil p.Cmd = nil
} }

View File

@ -184,7 +184,3 @@ func writeNewHardLink(fpath string, target string) error {
} }
return nil return nil
} }
func isSymlink(fi os.FileInfo) bool {
return fi.Mode()&os.ModeSymlink != 0
}

View File

@ -50,7 +50,6 @@ func ParseGitURL(u string) (*url.URL, error) {
} }
type Git struct { type Git struct {
cmd *exec.Cmd
GitDir string GitDir string
Env []string Env []string
} }

View File

@ -24,7 +24,7 @@ import (
func EncodeSha1Hex(str string) string { func EncodeSha1Hex(str string) string {
h := sha1.New() h := sha1.New()
// TODO(sgotti) must handle write errors // TODO(sgotti) must handle write errors
h.Write([]byte(str)) _, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }
@ -32,6 +32,6 @@ func EncodeSha1Hex(str string) string {
func EncodeSha256Hex(str string) string { func EncodeSha256Hex(str string) string {
h := sha256.New() h := sha256.New()
// TODO(sgotti) must handle write errors // TODO(sgotti) must handle write errors
h.Write([]byte(str)) _, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }

View File

@ -51,8 +51,8 @@ func CompareStringSliceNoOrder(a []string, b []string) bool {
a = append([]string(nil), a...) a = append([]string(nil), a...)
b = append([]string(nil), b...) b = append([]string(nil), b...)
sort.Sort(sort.StringSlice(a)) sort.Strings(a)
sort.Sort(sort.StringSlice(b)) sort.Strings(b)
for i, v := range a { for i, v := range a {
if v != b[i] { if v != b[i] {