mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Enable addtional linters (#34085)
enable mirror, usestdlibbars and perfsprint part of: https://github.com/go-gitea/gitea/issues/34083 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -53,11 +53,11 @@ func generatePathTokens(input analysis.TokenStream, reversed bool) analysis.Toke
|
||||
|
||||
for i := 0; i < len(input); i++ {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(string(input[0].Term))
|
||||
sb.Write(input[0].Term)
|
||||
|
||||
for j := 1; j < i; j++ {
|
||||
sb.WriteString("/")
|
||||
sb.WriteString(string(input[j].Term))
|
||||
sb.Write(input[j].Term)
|
||||
}
|
||||
|
||||
term := sb.String()
|
||||
|
@@ -5,7 +5,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -48,13 +48,13 @@ func (d *dummyIndexer) SupportedSearchModes() []indexer.SearchMode {
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *RepoChanges) error {
|
||||
return fmt.Errorf("indexer is not ready")
|
||||
return errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Delete(ctx context.Context, repoID int64) error {
|
||||
return fmt.Errorf("indexer is not ready")
|
||||
return errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Search(ctx context.Context, opts *SearchOptions) (int64, []*SearchResult, []*SearchResultLanguages, error) {
|
||||
return 0, nil, nil, fmt.Errorf("indexer is not ready")
|
||||
return 0, nil, nil, errors.New("indexer is not ready")
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ package bleve
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"code.gitea.io/gitea/modules/indexer/internal"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@@ -39,11 +39,11 @@ func NewIndexer(indexDir string, version int, mappingGetter func() (mapping.Inde
|
||||
// Init initializes the indexer
|
||||
func (i *Indexer) Init(_ context.Context) (bool, error) {
|
||||
if i == nil {
|
||||
return false, fmt.Errorf("cannot init nil indexer")
|
||||
return false, errors.New("cannot init nil indexer")
|
||||
}
|
||||
|
||||
if i.Indexer != nil {
|
||||
return false, fmt.Errorf("indexer is already initialized")
|
||||
return false, errors.New("indexer is already initialized")
|
||||
}
|
||||
|
||||
indexer, version, err := openIndexer(i.indexDir, i.version)
|
||||
@@ -83,10 +83,10 @@ func (i *Indexer) Init(_ context.Context) (bool, error) {
|
||||
// Ping checks if the indexer is available
|
||||
func (i *Indexer) Ping(_ context.Context) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("cannot ping nil indexer")
|
||||
return errors.New("cannot ping nil indexer")
|
||||
}
|
||||
if i.Indexer == nil {
|
||||
return fmt.Errorf("indexer is not initialized")
|
||||
return errors.New("indexer is not initialized")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ package elasticsearch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/indexer/internal"
|
||||
@@ -36,10 +37,10 @@ func NewIndexer(url, indexName string, version int, mapping string) *Indexer {
|
||||
// Init initializes the indexer
|
||||
func (i *Indexer) Init(ctx context.Context) (bool, error) {
|
||||
if i == nil {
|
||||
return false, fmt.Errorf("cannot init nil indexer")
|
||||
return false, errors.New("cannot init nil indexer")
|
||||
}
|
||||
if i.Client != nil {
|
||||
return false, fmt.Errorf("indexer is already initialized")
|
||||
return false, errors.New("indexer is already initialized")
|
||||
}
|
||||
|
||||
client, err := i.initClient()
|
||||
@@ -66,10 +67,10 @@ func (i *Indexer) Init(ctx context.Context) (bool, error) {
|
||||
// Ping checks if the indexer is available
|
||||
func (i *Indexer) Ping(ctx context.Context) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("cannot ping nil indexer")
|
||||
return errors.New("cannot ping nil indexer")
|
||||
}
|
||||
if i.Client == nil {
|
||||
return fmt.Errorf("indexer is not initialized")
|
||||
return errors.New("indexer is not initialized")
|
||||
}
|
||||
|
||||
resp, err := i.Client.ClusterHealth().Do(ctx)
|
||||
|
@@ -5,7 +5,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Indexer defines an basic indexer interface
|
||||
@@ -27,11 +27,11 @@ func NewDummyIndexer() Indexer {
|
||||
type dummyIndexer struct{}
|
||||
|
||||
func (d *dummyIndexer) Init(ctx context.Context) (bool, error) {
|
||||
return false, fmt.Errorf("indexer is not ready")
|
||||
return false, errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Ping(ctx context.Context) error {
|
||||
return fmt.Errorf("indexer is not ready")
|
||||
return errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Close() {}
|
||||
|
@@ -5,6 +5,7 @@ package meilisearch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/meilisearch/meilisearch-go"
|
||||
@@ -33,11 +34,11 @@ func NewIndexer(url, apiKey, indexName string, version int, settings *meilisearc
|
||||
// Init initializes the indexer
|
||||
func (i *Indexer) Init(_ context.Context) (bool, error) {
|
||||
if i == nil {
|
||||
return false, fmt.Errorf("cannot init nil indexer")
|
||||
return false, errors.New("cannot init nil indexer")
|
||||
}
|
||||
|
||||
if i.Client != nil {
|
||||
return false, fmt.Errorf("indexer is already initialized")
|
||||
return false, errors.New("indexer is already initialized")
|
||||
}
|
||||
|
||||
i.Client = meilisearch.New(i.url, meilisearch.WithAPIKey(i.apiKey))
|
||||
@@ -62,10 +63,10 @@ func (i *Indexer) Init(_ context.Context) (bool, error) {
|
||||
// Ping checks if the indexer is available
|
||||
func (i *Indexer) Ping(ctx context.Context) error {
|
||||
if i == nil {
|
||||
return fmt.Errorf("cannot ping nil indexer")
|
||||
return errors.New("cannot ping nil indexer")
|
||||
}
|
||||
if i.Client == nil {
|
||||
return fmt.Errorf("indexer is not initialized")
|
||||
return errors.New("indexer is not initialized")
|
||||
}
|
||||
resp, err := i.Client.Health()
|
||||
if err != nil {
|
||||
|
@@ -5,7 +5,6 @@ package elasticsearch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -96,7 +95,7 @@ func (b *Indexer) Index(ctx context.Context, issues ...*internal.IndexerData) er
|
||||
issue := issues[0]
|
||||
_, err := b.inner.Client.Index().
|
||||
Index(b.inner.VersionedIndexName()).
|
||||
Id(fmt.Sprintf("%d", issue.ID)).
|
||||
Id(strconv.FormatInt(issue.ID, 10)).
|
||||
BodyJson(issue).
|
||||
Do(ctx)
|
||||
return err
|
||||
@@ -107,7 +106,7 @@ func (b *Indexer) Index(ctx context.Context, issues ...*internal.IndexerData) er
|
||||
reqs = append(reqs,
|
||||
elastic.NewBulkIndexRequest().
|
||||
Index(b.inner.VersionedIndexName()).
|
||||
Id(fmt.Sprintf("%d", issue.ID)).
|
||||
Id(strconv.FormatInt(issue.ID, 10)).
|
||||
Doc(issue),
|
||||
)
|
||||
}
|
||||
@@ -126,7 +125,7 @@ func (b *Indexer) Delete(ctx context.Context, ids ...int64) error {
|
||||
} else if len(ids) == 1 {
|
||||
_, err := b.inner.Client.Delete().
|
||||
Index(b.inner.VersionedIndexName()).
|
||||
Id(fmt.Sprintf("%d", ids[0])).
|
||||
Id(strconv.FormatInt(ids[0], 10)).
|
||||
Do(ctx)
|
||||
return err
|
||||
}
|
||||
@@ -136,7 +135,7 @@ func (b *Indexer) Delete(ctx context.Context, ids ...int64) error {
|
||||
reqs = append(reqs,
|
||||
elastic.NewBulkDeleteRequest().
|
||||
Index(b.inner.VersionedIndexName()).
|
||||
Id(fmt.Sprintf("%d", id)),
|
||||
Id(strconv.FormatInt(id, 10)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"code.gitea.io/gitea/modules/indexer"
|
||||
"code.gitea.io/gitea/modules/indexer/internal"
|
||||
@@ -36,13 +36,13 @@ func (d *dummyIndexer) SupportedSearchModes() []indexer.SearchMode {
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Index(_ context.Context, _ ...*IndexerData) error {
|
||||
return fmt.Errorf("indexer is not ready")
|
||||
return errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Delete(_ context.Context, _ ...int64) error {
|
||||
return fmt.Errorf("indexer is not ready")
|
||||
return errors.New("indexer is not ready")
|
||||
}
|
||||
|
||||
func (d *dummyIndexer) Search(_ context.Context, _ *SearchOptions) (*SearchResult, error) {
|
||||
return nil, fmt.Errorf("indexer is not ready")
|
||||
return nil, errors.New("indexer is not ready")
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
@@ -31,7 +31,7 @@ func handler(items ...int64) []int64 {
|
||||
func initStatsQueue() error {
|
||||
statsQueue = queue.CreateUniqueQueue(graceful.GetManager().ShutdownContext(), "repo_stats_update", handler)
|
||||
if statsQueue == nil {
|
||||
return fmt.Errorf("unable to create repo_stats_update queue")
|
||||
return errors.New("unable to create repo_stats_update queue")
|
||||
}
|
||||
go graceful.GetManager().RunWithCancel(statsQueue)
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user