Skip to content

Commit

Permalink
fix: lint error from golangci-lint (appleboy#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored May 27, 2018
1 parent bed421f commit abd8316
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pipeline:
build:
image: appleboy/golang-testing:${GO_VERSION}
commands:
- make embedmd
- make embedmd-check
- make vet
- make lint
- make fmt-check
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ GOFMT ?= gofmt "-s"
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOFILES := find . -name "*.go" -type f -not -path "./vendor/*"

embedmd:
embedmd-check:
@hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/campoy/embedmd; \
fi
embedmd -d *.md

embedmd:
@hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/campoy/embedmd; \
fi
embedmd -w *.md

fmt:
$(GOFILES) | xargs $(GOFMT) -w

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Please see [the example file](example/server.go) and you can use `ExtractClaims`
package main

import (
"log"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -80,7 +81,7 @@ func main() {
return nil, false
},
Authorizator: func(user interface{}, c *gin.Context) bool {
if user.(string) == "admin" {
if v, ok := user.(string); ok && v == "admin" {
return true
}

Expand Down Expand Up @@ -119,7 +120,9 @@ func main() {
auth.GET("/refresh_token", authMiddleware.RefreshHandler)
}

http.ListenAndServe(":"+port, r)
if err := http.ListenAndServe(":"+port, r); err != nil {
log.Fatal(err)
}
}
```

Expand Down
4 changes: 0 additions & 4 deletions auth_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,11 @@ func (mw *GinJWTMiddleware) MiddlewareFunc() gin.HandlerFunc {
if err := mw.MiddlewareInit(); err != nil {
return func(c *gin.Context) {
mw.unauthorized(c, http.StatusInternalServerError, mw.HTTPStatusMessageFunc(err, nil))
return
}
}

return func(c *gin.Context) {
mw.middlewareImpl(c)
return
}
}

Expand Down Expand Up @@ -538,6 +536,4 @@ func (mw *GinJWTMiddleware) unauthorized(c *gin.Context, code int, message strin
c.Abort()

mw.Unauthorized(c, code, message)

return
}
7 changes: 5 additions & 2 deletions example/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -52,7 +53,7 @@ func main() {
return nil, false
},
Authorizator: func(user interface{}, c *gin.Context) bool {
if user.(string) == "admin" {
if v, ok := user.(string); ok && v == "admin" {
return true
}

Expand Down Expand Up @@ -91,5 +92,7 @@ func main() {
auth.GET("/refresh_token", authMiddleware.RefreshHandler)
}

http.ListenAndServe(":"+port, r)
if err := http.ListenAndServe(":"+port, r); err != nil {
log.Fatal(err)
}
}

0 comments on commit abd8316

Please sign in to comment.