Skip to content

Commit 13fac88

Browse files
authored
Merge pull request #7 from rhd-gitops-example/add-lint-to-travis
Add ci-linter to the Travis setup
2 parents aec2527 + 1a84667 commit 13fac88

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
language: go
22
go: 1.14
33
sudo: false
4+
before_script:
5+
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh
46
cache:
57
directories:
68
- $GOPATH/pkg/mod
9+
script:
10+
- ./bin/golangci-lint run
11+
- go test -race ./...

pkg/health/health.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package health
22

33
import (
44
"encoding/json"
5+
"log"
56
"net/http"
67
)
78

@@ -10,7 +11,9 @@ var GitRevision = "unknown"
1011
// Handler returns the value of GitRevision in simple struct.
1112
func Handler(w http.ResponseWriter, r *http.Request) {
1213
w.Header().Set("Content-Type", "application/json")
13-
json.NewEncoder(w).Encode(struct {
14+
if err := json.NewEncoder(w).Encode(struct {
1415
Version string `json:"version"`
15-
}{Version: GitRevision})
16+
}{Version: GitRevision}); err != nil {
17+
log.Printf("failed to encode Health response: %s", err)
18+
}
1619
}

pkg/httpapi/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@ func refFromQuery(v url.Values) string {
209209
func marshalResponse(w http.ResponseWriter, v interface{}) {
210210
w.Header().Set("Content-Type", "application/json")
211211
w.Header().Set("Access-Control-Allow-Origin", "*")
212-
json.NewEncoder(w).Encode(v)
212+
if err := json.NewEncoder(w).Encode(v); err != nil {
213+
log.Printf("failed to encode response: %s", err)
214+
}
213215
}

pkg/httpapi/authorization.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import (
77
)
88

99
const (
10-
authHeader = "Authorization"
11-
authTokenCtxKey = "auth-token"
10+
authHeader = "Authorization"
1211
)
1312

13+
type authTokenCtxKey struct{}
14+
1415
// AuthToken gets the auth token from the context.
1516
func AuthToken(ctx context.Context) string {
16-
return ctx.Value(authTokenCtxKey).(string)
17+
return ctx.Value(authTokenCtxKey{}).(string)
1718
}
1819

1920
// WithAuthToken sets the auth token into the context.
2021
func WithAuthToken(ctx context.Context, t string) context.Context {
21-
return context.WithValue(ctx, authTokenCtxKey, t)
22+
return context.WithValue(ctx, authTokenCtxKey{}, t)
2223
}
2324

2425
// AuthenticationMiddleware wraps an http.Handler and checks for the presence of

pkg/parser/parser.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ import (
1313
"github.com/rhd-gitops-example/gitops-backend/pkg/gitfs"
1414
)
1515

16-
const (
17-
serviceLabel = "app.kubernetes.io/name"
18-
appLabel = "app.kubernetes.io/part-of"
19-
)
20-
2116
// ParseFromGit takes a go-git CloneOptions struct and a filepath, and extracts
2217
// the service configuration from there.
2318
func ParseFromGit(path string, opts *git.CloneOptions) ([]*Resource, error) {

0 commit comments

Comments
 (0)