Skip to content

Commit 74654f2

Browse files
ferhatelmasLinkinStars
authored andcommitted
feat: add golangci-lint into lint target
* replace empty interface with any * run fmt via golangci-lint related to #1432 Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 92de2ef commit 74654f2

32 files changed

Lines changed: 125 additions & 90 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ vendor/
2828
/answer-data/
2929
/answer
3030
/new_answer
31-
31+
build/tools/
3232
dist/
3333

3434
# Lint setup generated file

.golangci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
version: "2"
19+
linters:
20+
default: none
21+
22+
formatters:
23+
enable:
24+
- gofmt
25+
settings:
26+
gofmt:
27+
simplify: true
28+
rewrite-rules:
29+
- pattern: 'interface{}'
30+
replacement: 'any'

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Revision=$(shell git rev-parse --short HEAD 2>/dev/null || echo "")
1010
GO_FLAGS=-ldflags="-X github.com/apache/answer/cmd.Version=$(VERSION) -X 'github.com/apache/answer/cmd.Revision=$(Revision)' -X 'github.com/apache/answer/cmd.Time=`date +%s`' -extldflags -static"
1111
GO=$(GO_ENV) "$(shell which go)"
1212

13+
GOLANGCI_VERSION ?= v2.6.2
14+
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)
15+
16+
GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)
17+
$(GOLANGCI):
18+
rm -f $(TOOLS_BIN)/golangci-lint*
19+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_VERSION)/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI_VERSION)
20+
mv $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)
21+
1322
build: generate
1423
@$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)
1524

@@ -50,8 +59,12 @@ install-ui-packages:
5059
ui:
5160
@cd ui && pnpm pre-install && pnpm build && cd -
5261

53-
lint: generate
62+
lint: generate $(GOLANGCI)
63+
@bash ./script/check-asf-header.sh
64+
$(GOLANGCI) run
65+
66+
lint-fix: generate $(GOLANGCI)
5467
@bash ./script/check-asf-header.sh
55-
@gofmt -w -l .
68+
$(GOLANGCI) run --fix
5669

5770
all: clean build

docs/docs.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8080,9 +8080,6 @@ const docTemplate = `{
80808080
"id": {
80818081
"type": "string"
80828082
},
8083-
"question_id": {
8084-
"type": "string"
8085-
},
80868083
"title": {
80878084
"type": "string"
80888085
}
@@ -10920,7 +10917,7 @@ const docTemplate = `{
1092010917
},
1092110918
"theme_config": {
1092210919
"type": "object",
10923-
"additionalProperties": true
10920+
"additionalProperties": {}
1092410921
}
1092510922
}
1092610923
},
@@ -10935,7 +10932,7 @@ const docTemplate = `{
1093510932
},
1093610933
"theme_config": {
1093710934
"type": "object",
10938-
"additionalProperties": true
10935+
"additionalProperties": {}
1093910936
},
1094010937
"theme_options": {
1094110938
"type": "array",

docs/swagger.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8053,9 +8053,6 @@
80538053
"id": {
80548054
"type": "string"
80558055
},
8056-
"question_id": {
8057-
"type": "string"
8058-
},
80598056
"title": {
80608057
"type": "string"
80618058
}
@@ -10893,7 +10890,7 @@
1089310890
},
1089410891
"theme_config": {
1089510892
"type": "object",
10896-
"additionalProperties": true
10893+
"additionalProperties": {}
1089710894
}
1089810895
}
1089910896
},
@@ -10908,7 +10905,7 @@
1090810905
},
1090910906
"theme_config": {
1091010907
"type": "object",
10911-
"additionalProperties": true
10908+
"additionalProperties": {}
1091210909
},
1091310910
"theme_options": {
1091410911
"type": "array",

docs/swagger.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ definitions:
399399
type: string
400400
id:
401401
type: string
402-
question_id:
403-
type: string
404402
title:
405403
type: string
406404
required:
@@ -2364,7 +2362,7 @@ definitions:
23642362
maxLength: 255
23652363
type: string
23662364
theme_config:
2367-
additionalProperties: true
2365+
additionalProperties: {}
23682366
type: object
23692367
required:
23702368
- theme
@@ -2376,7 +2374,7 @@ definitions:
23762374
theme:
23772375
type: string
23782376
theme_config:
2379-
additionalProperties: true
2377+
additionalProperties: {}
23802378
type: object
23812379
theme_options:
23822380
items:

internal/base/handler/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
// HandleResponse Handle response body
34-
func HandleResponse(ctx *gin.Context, err error, data interface{}) {
34+
func HandleResponse(ctx *gin.Context, err error, data any) {
3535
lang := GetLang(ctx)
3636
// no error
3737
if err == nil {
@@ -61,7 +61,7 @@ func HandleResponse(ctx *gin.Context, err error, data interface{}) {
6161
}
6262

6363
// BindAndCheck bind request and check
64-
func BindAndCheck(ctx *gin.Context, data interface{}) bool {
64+
func BindAndCheck(ctx *gin.Context, data any) bool {
6565
lang := GetLang(ctx)
6666
ctx.Set(constant.AcceptLanguageFlag, lang)
6767
if err := ctx.ShouldBind(data); err != nil {
@@ -79,7 +79,7 @@ func BindAndCheck(ctx *gin.Context, data interface{}) bool {
7979
}
8080

8181
// BindAndCheckReturnErr bind request and check
82-
func BindAndCheckReturnErr(ctx *gin.Context, data interface{}) (errFields []*validator.FormErrorField) {
82+
func BindAndCheckReturnErr(ctx *gin.Context, data any) (errFields []*validator.FormErrorField) {
8383
lang := GetLang(ctx)
8484
if err := ctx.ShouldBind(data); err != nil {
8585
log.Errorf("http_handle BindAndCheck fail, %s", err.Error())

internal/base/handler/response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type RespBody struct {
3434
// response message
3535
Message string `json:"msg"`
3636
// response data
37-
Data interface{} `json:"data"`
37+
Data any `json:"data"`
3838
}
3939

4040
// TrMsg translate the reason cause as a message
@@ -63,7 +63,7 @@ func NewRespBodyFromError(e *errors.Error) *RespBody {
6363
}
6464

6565
// NewRespBodyData new response body with data
66-
func NewRespBodyData(code int, reason string, data interface{}) *RespBody {
66+
func NewRespBodyData(code int, reason string, data any) *RespBody {
6767
return &RespBody{
6868
Code: code,
6969
Reason: reason,

internal/base/pager/pager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
// Help xorm page helper
30-
func Help(page, pageSize int, rowsSlicePtr interface{}, rowElement interface{}, session *xorm.Session) (total int64, err error) {
30+
func Help(page, pageSize int, rowsSlicePtr any, rowElement any, session *xorm.Session) (total int64, err error) {
3131
page, pageSize = ValPageAndPageSize(page, pageSize)
3232

3333
sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))

internal/base/pager/pagination.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
// PageModel page model
2727
type PageModel struct {
28-
Count int64 `json:"count"`
29-
List interface{} `json:"list"`
28+
Count int64 `json:"count"`
29+
List any `json:"list"`
3030
}
3131

3232
// PageCond page condition
@@ -36,7 +36,7 @@ type PageCond struct {
3636
}
3737

3838
// NewPageModel new page model
39-
func NewPageModel(totalRecords int64, records interface{}) *PageModel {
39+
func NewPageModel(totalRecords int64, records any) *PageModel {
4040
sliceValue := reflect.Indirect(reflect.ValueOf(records))
4141
if sliceValue.Kind() != reflect.Slice {
4242
panic("not a slice")

0 commit comments

Comments
 (0)