Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed May 11, 2023
1 parent 0833b5a commit 18fd161
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion auth/authenticator_test.go
Expand Up @@ -47,7 +47,7 @@ type TestBasicUnauthorizer struct {
BasicAuthenticator
}

func (a *TestBasicUnauthorizer) OnUnauthorized(response *goyave.Response, request *goyave.Request, err error) {
func (a *TestBasicUnauthorizer) OnUnauthorized(response *goyave.Response, _ *goyave.Request, err error) {
response.JSON(http.StatusUnauthorized, map[string]string{"custom error key": err.Error()})
}

Expand Down
6 changes: 3 additions & 3 deletions database/database.go
Expand Up @@ -72,7 +72,7 @@ func SetConnection(dialector gorm.Dialector) (*gorm.DB, error) {
mu.Lock()
defer mu.Unlock()
if dbConnection != nil {
if err := close(); err != nil {
if err := closeDB(); err != nil {
return nil, err
}
}
Expand All @@ -86,7 +86,7 @@ func SetConnection(dialector gorm.Dialector) (*gorm.DB, error) {
return dbConnection, nil
}

func close() error {
func closeDB() error {
var err error
if dbConnection != nil {
db, _ := dbConnection.DB()
Expand All @@ -100,7 +100,7 @@ func close() error {
func Close() error {
mu.Lock()
defer mu.Unlock()
return close()
return closeDB()
}

// AddInitializer adds a database connection initializer function.
Expand Down
2 changes: 1 addition & 1 deletion goyave_test.go
Expand Up @@ -22,7 +22,7 @@ type GoyaveTestSuite struct {
TestSuite
}

func helloHandler(response *Response, request *Request) {
func helloHandler(response *Response, _ *Request) {
response.String(http.StatusOK, "Hi!")
}

Expand Down
8 changes: 4 additions & 4 deletions lang/lang.go
Expand Up @@ -198,17 +198,17 @@ func Get(lang string, line string, placeholders ...string) string {
}
return convertEmptyLine(line, languages[lang].validation.rules[strings.Join(path[2:], ".")], placeholders)
case "fields":
len := len(path)
if len < 3 {
length := len(path)
if length < 3 {
return line
}
attr := languages[lang].validation.fields[path[2]]
if len == 4 {
if length == 4 {
if attr.Rules == nil {
return line
}
return convertEmptyLine(line, attr.Rules[path[3]], placeholders)
} else if len == 3 {
} else if length == 3 {
return convertEmptyLine(line, attr.Name, placeholders)
} else {
return line
Expand Down
6 changes: 3 additions & 3 deletions router.go
Expand Up @@ -68,7 +68,7 @@ var (
// print stacktrace in the console.
// If debugging is not enabled, writes `{"error": "Internal Server Error"}`
// to the response.
func PanicStatusHandler(response *Response, request *Request) {
func PanicStatusHandler(response *Response, _ *Request) {
response.error(response.GetError())
if response.empty {
message := map[string]string{
Expand All @@ -80,7 +80,7 @@ func PanicStatusHandler(response *Response, request *Request) {

// ErrorStatusHandler a generic status handler for non-success codes.
// Writes the corresponding status message to the response.
func ErrorStatusHandler(response *Response, request *Request) {
func ErrorStatusHandler(response *Response, _ *Request) {
message := map[string]string{
"error": http.StatusText(response.GetStatus()),
}
Expand All @@ -89,7 +89,7 @@ func ErrorStatusHandler(response *Response, request *Request) {

// ValidationStatusHandler for HTTP 400 and HTTP 422 errors.
// Writes the validation errors to the response.
func ValidationStatusHandler(response *Response, request *Request) {
func ValidationStatusHandler(response *Response, _ *Request) {
message := map[string]interface{}{"validationError": response.GetError()}
response.JSON(response.GetStatus(), message)
}
Expand Down
7 changes: 6 additions & 1 deletion testsuite_test.go
Expand Up @@ -207,29 +207,33 @@ func (suite *CustomTestSuite) TestRequests() {
if err == nil {
suite.Equal("post", string(suite.GetBody(resp)))
}
resp.Body.Close()
resp, err = suite.Put("/put", nil, strings.NewReader("field=value"))
suite.Nil(err)
if err == nil {
suite.Equal("put", string(suite.GetBody(resp)))
}
resp.Body.Close()
resp, err = suite.Patch("/patch", nil, strings.NewReader("field=value"))
suite.Nil(err)
if err == nil {
suite.Equal("patch", string(suite.GetBody(resp)))
}
resp.Body.Close()
resp, err = suite.Delete("/delete", nil, strings.NewReader("field=value"))
suite.Nil(err)
if err == nil {
suite.Equal("delete", string(suite.GetBody(resp)))
}
resp.Body.Close()

// Headers
resp, err = suite.Get("/headers", map[string]string{"Accept-Language": "en-US"})
suite.Nil(err)
if err == nil {
suite.Equal("en-US", string(suite.GetBody(resp)))
resp.Body.Close()
}
resp.Body.Close()

// Errors
resp, err = suite.Get("invalid", nil)
Expand Down Expand Up @@ -368,6 +372,7 @@ func (suite *CustomTestSuite) TestMultipartForm() {
suite.Equal("hello world", json["field"])
}
}
resp.Body.Close()
})
}

Expand Down
2 changes: 1 addition & 1 deletion validation/placeholder.go
Expand Up @@ -55,7 +55,7 @@ func replaceField(field, language string) string {
return attr
}

func simpleParameterPlaceholder(field string, language string, ctx *Context) string {
func simpleParameterPlaceholder(_ string, _ string, ctx *Context) string {
return ctx.Rule.Params[0]
}

Expand Down
2 changes: 1 addition & 1 deletion websocket/conn.go
Expand Up @@ -42,7 +42,7 @@ func (c *Conn) GetCloseHandshakeTimeout() time.Duration {
return c.timeout
}

func (c *Conn) closeHandler(code int, text string) error {
func (c *Conn) closeHandler(_ int, _ string) error {
c.waitClose <- struct{}{}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions websocket/websocket.go
Expand Up @@ -85,7 +85,7 @@ type Handler func(*Conn, *goyave.Request) error
// These handlers are called when an error occurs while the protocol switching.
type UpgradeErrorHandler func(response *goyave.Response, request *goyave.Request, status int, reason error)

func defaultUpgradeErrorHandler(response *goyave.Response, request *goyave.Request, status int, reason error) {
func defaultUpgradeErrorHandler(response *goyave.Response, _ *goyave.Request, status int, reason error) {
text := http.StatusText(status)
if config.GetBool("app.debug") && reason != nil {
text = reason.Error()
Expand Down Expand Up @@ -243,7 +243,7 @@ type adapter struct {
request *goyave.Request
}

func (a *adapter) onError(w http.ResponseWriter, r *http.Request, status int, reason error) {
func (a *adapter) onError(w http.ResponseWriter, _ *http.Request, status int, reason error) {
if status == http.StatusInternalServerError {
panic(reason)
}
Expand Down

0 comments on commit 18fd161

Please sign in to comment.