1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

format with gofumpt (#18184)

* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
This commit is contained in:
6543
2022-01-20 18:46:10 +01:00
committed by GitHub
parent 1d98d205f5
commit 54e9ee37a7
423 changed files with 1585 additions and 1758 deletions

View File

@@ -38,8 +38,10 @@ import (
"github.com/go-enry/go-enry/v2"
)
const unicodeNormalizeName = "unicodeNormalize"
const maxBatchSize = 16
const (
unicodeNormalizeName = "unicodeNormalize"
maxBatchSize = 16
)
// numericEqualityQuery a numeric equality query for the given value and field
func numericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
@@ -158,9 +160,7 @@ func createBleveIndexer(path string, latestVersion int) (bleve.Index, error) {
return indexer, nil
}
var (
_ Indexer = &BleveIndexer{}
)
var _ Indexer = &BleveIndexer{}
// BleveIndexer represents a bleve indexer implementation
type BleveIndexer struct {
@@ -337,7 +337,7 @@ func (b *BleveIndexer) Search(repoIDs []int64, language, keyword string, page, p
}
if len(repoIDs) > 0 {
var repoQueries = make([]query.Query, 0, len(repoIDs))
repoQueries := make([]query.Query, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoQueries = append(repoQueries, numericEqualityQuery(repoID, "RepoID"))
}

View File

@@ -35,9 +35,7 @@ const (
esMultiMatchTypePhrasePrefix = "phrase_prefix"
)
var (
_ Indexer = &ElasticSearchIndexer{}
)
var _ Indexer = &ElasticSearchIndexer{}
// ElasticSearchIndexer implements Indexer interface
type ElasticSearchIndexer struct {
@@ -131,7 +129,7 @@ func (b *ElasticSearchIndexer) init() (bool, error) {
return false, err
}
if !exists {
var mapping = defaultMapping
mapping := defaultMapping
createIndex, err := b.client.CreateIndex(b.realIndexerName()).BodyString(mapping).Do(ctx)
if err != nil {
@@ -327,7 +325,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
}
repoID, fileName := parseIndexerID(hit.Id)
var res = make(map[string]interface{})
res := make(map[string]interface{})
if err := json.Unmarshal(hit.Source, &res); err != nil {
return 0, nil, nil, err
}
@@ -378,7 +376,7 @@ func (b *ElasticSearchIndexer) Search(repoIDs []int64, language, keyword string,
query := elastic.NewBoolQuery()
query = query.Must(kwQuery)
if len(repoIDs) > 0 {
var repoStrs = make([]interface{}, 0, len(repoIDs))
repoStrs := make([]interface{}, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoStrs = append(repoStrs, repoID)
}

View File

@@ -73,7 +73,7 @@ func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
if err != nil {
return nil, err
}
var idxCount = 0
idxCount := 0
updates := make([]fileUpdate, len(entries))
for _, entry := range entries {
if isIndexable(entry) {

View File

@@ -78,9 +78,7 @@ type IndexerData struct {
RepoID int64
}
var (
indexerQueue queue.UniqueQueue
)
var indexerQueue queue.UniqueQueue
func index(ctx context.Context, indexer Indexer, repoID int64) error {
repo, err := repo_model.GetRepositoryByID(repoID)

View File

@@ -25,45 +25,43 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
var repoID int64 = 1
err := index(git.DefaultContext, indexer, repoID)
assert.NoError(t, err)
var (
keywords = []struct {
RepoIDs []int64
Keyword string
IDs []int64
Langs int
}{
{
RepoIDs: nil,
Keyword: "Description",
IDs: []int64{repoID},
Langs: 1,
},
{
RepoIDs: []int64{2},
Keyword: "Description",
IDs: []int64{},
Langs: 0,
},
{
RepoIDs: nil,
Keyword: "repo1",
IDs: []int64{repoID},
Langs: 1,
},
{
RepoIDs: []int64{2},
Keyword: "repo1",
IDs: []int64{},
Langs: 0,
},
{
RepoIDs: nil,
Keyword: "non-exist",
IDs: []int64{},
Langs: 0,
},
}
)
keywords := []struct {
RepoIDs []int64
Keyword string
IDs []int64
Langs int
}{
{
RepoIDs: nil,
Keyword: "Description",
IDs: []int64{repoID},
Langs: 1,
},
{
RepoIDs: []int64{2},
Keyword: "Description",
IDs: []int64{},
Langs: 0,
},
{
RepoIDs: nil,
Keyword: "repo1",
IDs: []int64{repoID},
Langs: 1,
},
{
RepoIDs: []int64{2},
Keyword: "repo1",
IDs: []int64{},
Langs: 0,
},
{
RepoIDs: nil,
Keyword: "non-exist",
IDs: []int64{},
Langs: 0,
},
}
for _, kw := range keywords {
t.Run(kw.Keyword, func(t *testing.T) {
@@ -72,7 +70,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
assert.EqualValues(t, len(kw.IDs), total)
assert.Len(t, langs, kw.Langs)
var ids = make([]int64, 0, len(res))
ids := make([]int64, 0, len(res))
for _, hit := range res {
ids = append(ids, hit.RepoID)
assert.EqualValues(t, "# repo1\n\nDescription for repo1", hit.Content)

View File

@@ -12,9 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
)
var (
indexer = newWrappedIndexer()
)
var indexer = newWrappedIndexer()
// ErrWrappedIndexerClosed is the error returned if the indexer was closed before it was ready
var ErrWrappedIndexerClosed = fmt.Errorf("Indexer closed before ready")
@@ -80,7 +78,6 @@ func (w *wrappedIndexer) Search(repoIDs []int64, language, keyword string, page,
return 0, nil, nil, err
}
return indexer.Search(repoIDs, language, keyword, page, pageSize, isMatch)
}
func (w *wrappedIndexer) Close() {