Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vendor/
/answer-data/
/answer
/new_answer

build/tools/
dist/

# Lint setup generated file
Expand Down
30 changes: 30 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

version: "2"
linters:
default: none

formatters:
enable:
- gofmt
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Revision=$(shell git rev-parse --short HEAD 2>/dev/null || echo "")
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"
GO=$(GO_ENV) "$(shell which go)"

GOLANGCI_VERSION ?= v2.6.2
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)

GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)
$(GOLANGCI):
rm -f $(TOOLS_BIN)/golangci-lint*
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_VERSION)/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI_VERSION)
mv $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)

build: generate
@$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)

Expand Down Expand Up @@ -50,8 +59,12 @@ install-ui-packages:
ui:
@cd ui && pnpm pre-install && pnpm build && cd -

lint: generate
lint: generate $(GOLANGCI)
@bash ./script/check-asf-header.sh
$(GOLANGCI) run

lint-fix: generate $(GOLANGCI)
@bash ./script/check-asf-header.sh
@gofmt -w -l .
$(GOLANGCI) run --fix

all: clean build
7 changes: 2 additions & 5 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8080,9 +8080,6 @@ const docTemplate = `{
"id": {
"type": "string"
},
"question_id": {
"type": "string"
},
"title": {
"type": "string"
}
Expand Down Expand Up @@ -10920,7 +10917,7 @@ const docTemplate = `{
},
"theme_config": {
"type": "object",
"additionalProperties": true
"additionalProperties": {}
}
}
},
Expand All @@ -10935,7 +10932,7 @@ const docTemplate = `{
},
"theme_config": {
"type": "object",
"additionalProperties": true
"additionalProperties": {}
},
"theme_options": {
"type": "array",
Expand Down
7 changes: 2 additions & 5 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8053,9 +8053,6 @@
"id": {
"type": "string"
},
"question_id": {
"type": "string"
},
"title": {
"type": "string"
}
Expand Down Expand Up @@ -10893,7 +10890,7 @@
},
"theme_config": {
"type": "object",
"additionalProperties": true
"additionalProperties": {}
}
}
},
Expand All @@ -10908,7 +10905,7 @@
},
"theme_config": {
"type": "object",
"additionalProperties": true
"additionalProperties": {}
},
"theme_options": {
"type": "array",
Expand Down
6 changes: 2 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ definitions:
type: string
id:
type: string
question_id:
type: string
title:
type: string
required:
Expand Down Expand Up @@ -2364,7 +2362,7 @@ definitions:
maxLength: 255
type: string
theme_config:
additionalProperties: true
additionalProperties: {}
type: object
required:
- theme
Expand All @@ -2376,7 +2374,7 @@ definitions:
theme:
type: string
theme_config:
additionalProperties: true
additionalProperties: {}
type: object
theme_options:
items:
Expand Down
6 changes: 3 additions & 3 deletions internal/base/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// HandleResponse Handle response body
func HandleResponse(ctx *gin.Context, err error, data interface{}) {
func HandleResponse(ctx *gin.Context, err error, data any) {
lang := GetLang(ctx)
// no error
if err == nil {
Expand Down Expand Up @@ -61,7 +61,7 @@ func HandleResponse(ctx *gin.Context, err error, data interface{}) {
}

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

// BindAndCheckReturnErr bind request and check
func BindAndCheckReturnErr(ctx *gin.Context, data interface{}) (errFields []*validator.FormErrorField) {
func BindAndCheckReturnErr(ctx *gin.Context, data any) (errFields []*validator.FormErrorField) {
lang := GetLang(ctx)
if err := ctx.ShouldBind(data); err != nil {
log.Errorf("http_handle BindAndCheck fail, %s", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions internal/base/handler/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type RespBody struct {
// response message
Message string `json:"msg"`
// response data
Data interface{} `json:"data"`
Data any `json:"data"`
}

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

// NewRespBodyData new response body with data
func NewRespBodyData(code int, reason string, data interface{}) *RespBody {
func NewRespBodyData(code int, reason string, data any) *RespBody {
return &RespBody{
Code: code,
Reason: reason,
Expand Down
2 changes: 1 addition & 1 deletion internal/base/pager/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

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

sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
Expand Down
6 changes: 3 additions & 3 deletions internal/base/pager/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

// PageModel page model
type PageModel struct {
Count int64 `json:"count"`
List interface{} `json:"list"`
Count int64 `json:"count"`
List any `json:"list"`
}

// PageCond page condition
Expand All @@ -36,7 +36,7 @@ type PageCond struct {
}

// NewPageModel new page model
func NewPageModel(totalRecords int64, records interface{}) *PageModel {
func NewPageModel(totalRecords int64, records any) *PageModel {
sliceValue := reflect.Indirect(reflect.ValueOf(records))
if sliceValue.Kind() != reflect.Slice {
panic("not a slice")
Expand Down
6 changes: 3 additions & 3 deletions internal/base/server/http_funcmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var funcMap = template.FuncMap{
"formatLinkNofollow": func(data string) template.HTML {
return template.HTML(FormatLinkNofollow(data))
},
"translator": func(la i18n.Language, data string, params ...interface{}) string {
"translator": func(la i18n.Language, data string, params ...any) string {
trans := translator.GlobalTrans.Tr(la, data)

if len(params) > 0 && len(params)%2 == 0 {
Expand Down Expand Up @@ -128,8 +128,8 @@ var funcMap = template.FuncMap{
trans = translator.GlobalTrans.Tr(la, "ui.dates.long_date_with_year")
return day.Format(timestamp, trans, tz)
},
"wrapComments": func(comments []*schema.GetCommentResp, la i18n.Language, tz string) map[string]interface{} {
return map[string]interface{}{
"wrapComments": func(comments []*schema.GetCommentResp, la i18n.Language, tz string) map[string]any {
return map[string]any{
"comments": comments,
"language": la,
"timezone": tz,
Expand Down
8 changes: 4 additions & 4 deletions internal/base/translator/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func NewTranslator(c *I18n) (tr i18n.Translator, err error) {

// parse the backend translation
originalTr := struct {
Backend map[string]map[string]interface{} `yaml:"backend"`
UI map[string]interface{} `yaml:"ui"`
Plugin map[string]interface{} `yaml:"plugin"`
Backend map[string]map[string]any `yaml:"backend"`
UI map[string]any `yaml:"ui"`
Plugin map[string]any `yaml:"plugin"`
}{}
if err = yaml.Unmarshal(buf, &originalTr); err != nil {
return nil, err
}
translation := make(map[string]interface{}, 0)
translation := make(map[string]any, 0)
for k, v := range originalTr.Backend {
translation[k] = v
}
Expand Down
4 changes: 2 additions & 2 deletions internal/base/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func GetValidatorByLang(lang i18n.Language) *MyValidator {
}

// Check /
func (m *MyValidator) Check(value interface{}) (errFields []*FormErrorField, err error) {
func (m *MyValidator) Check(value any) (errFields []*FormErrorField, err error) {
defer func() {
if len(errFields) == 0 {
return
Expand Down Expand Up @@ -261,7 +261,7 @@ type Checker interface {
Check() (errField []*FormErrorField, err error)
}

func getObjectTagByFieldName(obj interface{}, fieldName string) (tag string) {
func getObjectTagByFieldName(obj any, fieldName string) (tag string) {
defer func() {
if err := recover(); err != nil {
log.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/install/install_from_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func initBaseInfo(env *Env) (err error) {
return requestAPI(req, "POST", "/installation/base-info", InitBaseInfo)
}

func requestAPI(req interface{}, method, url string, handlerFunc gin.HandlerFunc) error {
func requestAPI(req any, method, url string, handlerFunc gin.HandlerFunc) error {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
body, _ := json.Marshal(req)
Expand Down
10 changes: 5 additions & 5 deletions internal/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (m *Mentor) initSiteInfoGeneralData() {
}

func (m *Mentor) initSiteInfoLoginConfig() {
loginConfig := map[string]interface{}{
loginConfig := map[string]any{
"allow_new_registrations": true,
"allow_email_registrations": true,
"allow_password_login": true,
Expand All @@ -223,7 +223,7 @@ func (m *Mentor) initSiteInfoLoginConfig() {
}

func (m *Mentor) initSiteInfoLegalConfig() {
legalConfig := map[string]interface{}{
legalConfig := map[string]any{
"external_content_display": m.userData.ExternalContentDisplay,
}
legalConfigDataBytes, _ := json.Marshal(legalConfig)
Expand All @@ -244,7 +244,7 @@ func (m *Mentor) initSiteInfoThemeConfig() {
}

func (m *Mentor) initSiteInfoSEOConfig() {
seoData := map[string]interface{}{
seoData := map[string]any{
"permalink": constant.PermalinkQuestionID,
"robots": defaultSEORobotTxt + m.userData.SiteURL + "/sitemap.xml",
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (m *Mentor) initSiteInfoUsersConfig() {
}

func (m *Mentor) initSiteInfoPrivilegeRank() {
privilegeRankData := map[string]interface{}{
privilegeRankData := map[string]any{
"level": schema.PrivilegeLevel2,
}
privilegeRankDataBytes, _ := json.Marshal(privilegeRankData)
Expand All @@ -288,7 +288,7 @@ func (m *Mentor) initSiteInfoPrivilegeRank() {
}

func (m *Mentor) initSiteInfoWrite() {
writeData := map[string]interface{}{
writeData := map[string]any{
"min_content": 6,
"restrict_answer": true,
"min_tags": 1,
Expand Down
2 changes: 1 addition & 1 deletion internal/migrations/init_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Sitemap: `
)

var (
tables = []interface{}{
tables = []any{
&entity.Activity{},
&entity.Answer{},
&entity.Collection{},
Expand Down
2 changes: 1 addition & 1 deletion internal/migrations/v25.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func addFileRecord(ctx context.Context, x *xorm.Engine) error {
if err != nil {
return fmt.Errorf("get legal config failed: %w", err)
}
legalConfig := make(map[string]interface{})
legalConfig := make(map[string]any)
if exist {
if err := json.Unmarshal([]byte(legalInfo.Content), &legalConfig); err != nil {
return fmt.Errorf("unmarshal legal config failed: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/migrations/v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func addNewAnswerNotification(ctx context.Context, x *xorm.Engine) error {
}
}

m := make(map[string]interface{})
m := make(map[string]any)
_ = json.Unmarshal([]byte(cond.Value), &m)
m["new_answer_title"] = "[{{.SiteName}}] {{.DisplayName}} answered your question"
m["new_answer_body"] = "<strong><a href='{{.AnswerUrl}}'>{{.QuestionTitle}}</a></strong><br><br>\n\n<small>{{.DisplayName}}:</small><br>\n<blockquote>{{.AnswerSummary}}</blockquote><br>\n<a href='{{.AnswerUrl}}'>View it on {{.SiteName}}</a><br><br>\n\n<small>You are receiving this because you authored the thread. <a href='{{.UnsubscribeUrl}}'>Unsubscribe</a></small>"
Expand Down
2 changes: 1 addition & 1 deletion internal/repo/meta/meta_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (mr *metaRepo) UpdateMeta(ctx context.Context, meta *entity.Meta) (err erro

// AddOrUpdateMetaByObjectIdAndKey if exist record with same objectID and key, update it. Or create a new one
func (mr *metaRepo) AddOrUpdateMetaByObjectIdAndKey(ctx context.Context, objectId, key string, f func(*entity.Meta, bool) (*entity.Meta, error)) error {
_, err := mr.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) {
_, err := mr.data.DB.Transaction(func(session *xorm.Session) (any, error) {
session = session.Context(ctx)

// 1. acquire meta entity with target object id and key
Expand Down
2 changes: 1 addition & 1 deletion internal/repo/plugin_config/plugin_user_config_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewPluginUserConfigRepo(data *data.Data) plugin_common.PluginUserConfigRepo

func (ur *pluginUserConfigRepo) SaveUserPluginConfig(ctx context.Context, userID string,
pluginSlugName, configValue string) (err error) {
_, err = ur.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) {
_, err = ur.data.DB.Transaction(func(session *xorm.Session) (any, error) {
session = session.Context(ctx)
old := &entity.PluginUserConfig{
UserID: userID,
Expand Down
2 changes: 1 addition & 1 deletion internal/repo/revision/revision_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (rr *revisionRepo) AddRevision(ctx context.Context, revision *entity.Revisi
if !rr.allowRecord(revision.ObjectType) {
return nil
}
_, err = rr.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) {
_, err = rr.data.DB.Transaction(func(session *xorm.Session) (any, error) {
session = session.Context(ctx)
_, err = session.Insert(revision)
if err != nil {
Expand Down
Loading