Skip to content

Commit

Permalink
No-ticket: add pre-commit hook. (#35)
Browse files Browse the repository at this point in the history
* No-ticket: add pre-commit hook.

* No-ticket: fix all via gofmt.
  • Loading branch information
vmelnik-ukraine authored and fabioesposito committed Mar 20, 2018
1 parent e5bdfe0 commit b43fe1b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: go
sudo: false
go:
- 1.9
before_install:
- diff -u <(echo -n) <(gofmt -d -s .)
install:
- go get github.com/golang/dep/cmd/dep
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
Expand Down
14 changes: 14 additions & 0 deletions pre-commit.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# 1. Rename the file to "pre-commit"
# 2. Put it under .git/hooks/
# 3. Make it executable

# cp pre-commit.dist .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

STAGED_GO_FILES=`git diff --cached --name-only | grep .go$`

if [ ! -z "$STAGED_GO_FILES" ]
then
gofmt -s -w $STAGED_GO_FILES && git add $STAGED_GO_FILES
fi
2 changes: 1 addition & 1 deletion ranger_http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewAPIClient(requestTimeout int) APIClientInterface {
// Get is issueing a GET request to the given url
func (client *apiClient) Get(url string) (*http.Response, error) {
res, err := client.client.Get(url)
if err != nil && res.StatusCode != http.StatusOK {
if err != nil && res.StatusCode != http.StatusOK {
return nil, fmt.Errorf(
"ApiClient.Get=Bad request,StatusCode=%d, URL=%s, Header: %+v", res.StatusCode, url, res.Header,
)
Expand Down
8 changes: 4 additions & 4 deletions ranger_http/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (

// ErrorResponse struct
type ErrorResponse struct {
Status int `json:"status"`
Status int `json:"status"`
Data *ErrorResponseData `json:"data"`
}

// ErrorResponseData struct
type ErrorResponseData struct {
ErrorCode string `json:"exception_type"`
Message string `json:"message"`
MoreInformation string `json:"more_information"`
MoreInformation string `json:"more_information"`
}

// NewErrorResponseData ...
func NewErrorResponseData(errorCode, message, moreInformation string) *ErrorResponseData {
return &ErrorResponseData{
ErrorCode: errorCode,
Message: message,
ErrorCode: errorCode,
Message: message,
MoreInformation: moreInformation,
}
}
Expand Down
2 changes: 1 addition & 1 deletion ranger_http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewHTTPServer(l ranger_logger.LoggerInterface) *Server {
router := httprouter.New()

return &Server{
Router: router,
Router: router,
}
}

Expand Down

0 comments on commit b43fe1b

Please sign in to comment.