diff options
Diffstat (limited to 'modules')
64 files changed, 109 insertions, 110 deletions
diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 738b1e4737..9bcef69de1 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -92,7 +92,7 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { priv: privParsed, pubID: pubID, } - return + return c, err } // NewRequest function @@ -110,7 +110,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) return } err = signer.SignRequest(c.priv, c.pubID, req, b) - return + return req, err } // Post function @@ -120,5 +120,5 @@ func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) { return } resp, err = c.client.Do(req) - return + return resp, err } diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go index 2144e7b47f..fc9775b0f0 100644 --- a/modules/activitypub/user_settings.go +++ b/modules/activitypub/user_settings.go @@ -35,11 +35,11 @@ func GetKeyPair(user *user_model.User) (pub, priv string, err error) { // GetPublicKey function returns a user's public key func GetPublicKey(user *user_model.User) (pub string, err error) { pub, _, err = GetKeyPair(user) - return + return pub, err } // GetPrivateKey function returns a user's private key func GetPrivateKey(user *user_model.User) (priv string, err error) { _, priv, err = GetKeyPair(user) - return + return priv, err } diff --git a/modules/base/natural_sort.go b/modules/base/natural_sort.go index 60db363df0..46cdd52932 100644 --- a/modules/base/natural_sort.go +++ b/modules/base/natural_sort.go @@ -55,7 +55,7 @@ func isDecimal(r rune) bool { } func compareByNumbers(str1 string, pos1 int, str2 string, pos2 int) (i1, i2 int, less, equal bool) { - var d1, d2 bool = true, true + d1, d2 := true, true var dec1, dec2 string for d1 || d2 { if d1 { diff --git a/modules/charset/charset_test.go b/modules/charset/charset_test.go index cfd5fb5696..6dd13c039d 100644 --- a/modules/charset/charset_test.go +++ b/modules/charset/charset_test.go @@ -296,11 +296,11 @@ func TestDetectEncoding(t *testing.T) { } func stringMustStartWith(t *testing.T, expected, value string) { - assert.Equal(t, expected, string(value[:len(expected)])) + assert.Equal(t, expected, value[:len(expected)]) } func stringMustEndWith(t *testing.T, expected, value string) { - assert.Equal(t, expected, string(value[len(value)-len(expected):])) + assert.Equal(t, expected, value[len(value)-len(expected):]) } func bytesMustStartWith(t *testing.T, expected, value []byte) { diff --git a/modules/charset/escape.go b/modules/charset/escape.go index 20a4bb2a10..9c1baafba3 100644 --- a/modules/charset/escape.go +++ b/modules/charset/escape.go @@ -222,15 +222,15 @@ readingloop: return } escaped.HasError = true - return + return escaped, err } func writeBroken(output io.Writer, bs []byte) (err error) { _, err = fmt.Fprintf(output, `<span class="broken-code-point"><%X></span>`, bs) - return + return err } func writeEscaped(output io.Writer, r rune) (err error) { _, err = fmt.Fprintf(output, `<span class="escaped-code-point" data-escaped="[U+%04X]"><span class="char">%c</span></span>`, r, r) - return + return err } diff --git a/modules/context/api.go b/modules/context/api.go index 33534dbf6b..558a9f51ee 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -340,7 +340,7 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) (cancel context } } - return + return cancel } } diff --git a/modules/context/private.go b/modules/context/private.go index fdc7751227..9e7977b5d5 100644 --- a/modules/context/private.go +++ b/modules/context/private.go @@ -82,5 +82,5 @@ func PrivateContexter() func(http.Handler) http.Handler { func OverrideContext(ctx *PrivateContext) (cancel context.CancelFunc) { // We now need to override the request context as the base for our work because even if the request is cancelled we have to continue this work ctx.Override, _, cancel = process.GetManager().AddTypedContext(graceful.GetManager().HammerContext(), fmt.Sprintf("PrivateContext: %s", ctx.Req.RequestURI), process.RequestProcessType, true) - return + return cancel } diff --git a/modules/context/repo.go b/modules/context/repo.go index 217cbd3dfc..1836373918 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -734,7 +734,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.Data["GoDocDirectory"] = prefix + "{/dir}" ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}" } - return + return cancel } // RepoRefType type of repo reference @@ -1001,7 +1001,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context return } ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount - return + return cancel } } diff --git a/modules/context/utils.go b/modules/context/utils.go index aea51cc5d6..a72c8b47e6 100644 --- a/modules/context/utils.go +++ b/modules/context/utils.go @@ -52,5 +52,5 @@ func parseTime(value string) (int64, error) { func prepareQueryArg(ctx *Context, name string) (value string, err error) { value, err = url.PathUnescape(ctx.FormString(name)) value = strings.TrimSpace(value) - return + return value, err } diff --git a/modules/convert/convert.go b/modules/convert/convert.go index c8cb23261e..c62b4303ed 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -257,7 +257,7 @@ func ToHook(repoLink string, w *webhook.Webhook) *api.Hook { return &api.Hook{ ID: w.ID, - Type: string(w.Type), + Type: w.Type, URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID), Active: w.IsActive, Config: config, diff --git a/modules/convert/issue.go b/modules/convert/issue.go index 35eff05229..5364367a80 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -123,7 +123,7 @@ func ToTrackedTime(t *issues_model.TrackedTime) (apiT *api.TrackedTime) { if t.User != nil { apiT.UserName = t.User.Name } - return + return apiT } // ToStopWatches convert Stopwatch list to api.StopWatches diff --git a/modules/doctor/fix16961.go b/modules/doctor/fix16961.go index 92c4418505..307cfcd9ff 100644 --- a/modules/doctor/fix16961.go +++ b/modules/doctor/fix16961.go @@ -216,7 +216,7 @@ func fixBrokenRepoUnit16961(repoUnit *repo_model.RepoUnit, bs []byte) (fixed boo return false, nil } - switch unit.Type(repoUnit.Type) { + switch repoUnit.Type { case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects: cfg := &repo_model.UnitConfig{} repoUnit.Config = cfg diff --git a/modules/eventsource/event.go b/modules/eventsource/event.go index 9fe20715e3..281a1bb135 100644 --- a/modules/eventsource/event.go +++ b/modules/eventsource/event.go @@ -18,7 +18,7 @@ func wrapNewlines(w io.Writer, prefix, value []byte) (sum int64, err error) { if len(value) == 0 { return } - n := 0 + var n int last := 0 for j := bytes.IndexByte(value, '\n'); j > -1; j = bytes.IndexByte(value[last:], '\n') { n, err = w.Write(prefix) @@ -45,7 +45,7 @@ func wrapNewlines(w io.Writer, prefix, value []byte) (sum int64, err error) { } n, err = w.Write([]byte("\n")) sum += int64(n) - return + return sum, err } // Event is an eventsource event, not all fields need to be set @@ -64,7 +64,7 @@ type Event struct { // The return value n is the number of bytes written. Any error encountered during the write is also returned. func (e *Event) WriteTo(w io.Writer) (int64, error) { sum := int64(0) - nint := 0 + var nint int n, err := wrapNewlines(w, []byte("event: "), []byte(e.Name)) sum += n if err != nil { diff --git a/modules/git/batch_reader.go b/modules/git/batch_reader.go index 902fa89718..feb0dd31be 100644 --- a/modules/git/batch_reader.go +++ b/modules/git/batch_reader.go @@ -176,12 +176,12 @@ func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err er typ = typ[:idx] size, err = strconv.ParseInt(sizeStr, 10, 64) - return + return sha, typ, size, err } // ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream. func ReadTagObjectID(rd *bufio.Reader, size int64) (string, error) { - id := "" + var id string var n int64 headerLoop: for { @@ -216,7 +216,7 @@ headerLoop: // ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream. func ReadTreeID(rd *bufio.Reader, size int64) (string, error) { - id := "" + var id string var n int64 headerLoop: for { @@ -328,7 +328,7 @@ func ParseTreeLine(rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fn // Deal with the 20-byte SHA idx = 0 for idx < 20 { - read := 0 + var read int read, err = rd.Read(shaBuf[idx:20]) n += read if err != nil { @@ -337,7 +337,7 @@ func ParseTreeLine(rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fn idx += read } sha = shaBuf - return + return mode, fname, sha, n, err } var callerPrefix string diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index 211c188559..89bb98162f 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -99,7 +99,7 @@ func (b *blobReader) Read(p []byte) (n int, err error) { } n, err = b.rd.Read(p) b.n -= int64(n) - return + return n, err } // Close implements io.Closer diff --git a/modules/git/commit.go b/modules/git/commit.go index 82b5e0b25d..82712dd1ef 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -418,7 +418,7 @@ func (c *Commit) LoadBranchName() (err error) { } c.Branch, err = c.GetBranchName() - return + return err } // GetTagName gets the current tag name for given commit diff --git a/modules/git/commit_info_nogogit.go b/modules/git/commit_info_nogogit.go index f430c672f8..ceab11adbb 100644 --- a/modules/git/commit_info_nogogit.go +++ b/modules/git/commit_info_nogogit.go @@ -157,7 +157,7 @@ func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, commit * if typ != "commit" { return nil, fmt.Errorf("unexpected type: %s for commit id: %s", typ, commitID) } - c, err = CommitFromReader(commit.repo, MustIDFromString(string(commitID)), io.LimitReader(batchReader, int64(size))) + c, err = CommitFromReader(commit.repo, MustIDFromString(commitID), io.LimitReader(batchReader, size)) if err != nil { return nil, err } diff --git a/modules/git/diff.go b/modules/git/diff.go index c9d68bb130..f75ebd4fd2 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -115,7 +115,7 @@ func ParseDiffHunkString(diffhunk string) (leftLine, leftHunk, rightLine, righHu rightLine = leftLine righHunk = leftHunk } - return + return leftLine, leftHunk, rightLine, righHunk } // Example: @@ -1,8 +1,9 @@ => [..., 1, 8, 1, 9] diff --git a/modules/git/pipeline/lfs_nogogit.go b/modules/git/pipeline/lfs_nogogit.go index a2b5dd0c96..061da8ca50 100644 --- a/modules/git/pipeline/lfs_nogogit.go +++ b/modules/git/pipeline/lfs_nogogit.go @@ -116,7 +116,7 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) { continue case "commit": // Read in the commit to get its tree and in case this is one of the last used commits - curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(string(commitID)), io.LimitReader(batchReader, int64(size))) + curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(string(commitID)), io.LimitReader(batchReader, size)) if err != nil { return nil, err } diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go index 596a91e803..1305e6f224 100644 --- a/modules/git/repo_attribute.go +++ b/modules/git/repo_attribute.go @@ -334,7 +334,7 @@ func (wr *lineSeparatedAttributeWriter) Write(p []byte) (n int, err error) { wr.tmp = []byte(remaining[3:]) break } - return l, fmt.Errorf("unexpected tail %s", string(remaining)) + return l, fmt.Errorf("unexpected tail %s", remaining) } _, _ = sb.WriteRune(rn) remaining = tail diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index df24d952a8..63c278c261 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -101,5 +101,5 @@ func (repo *Repository) Close() (err error) { repo.checkReader = nil repo.checkWriter = nil } - return + return err } diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index bc58991085..2983a35ca5 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -95,7 +95,7 @@ func callShowRef(ctx context.Context, repoPath, prefix, arg string, skip, limit return nil }) - return + return branchNames, countAll, err } func walkShowRef(ctx context.Context, repoPath, arg string, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) { diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index 3c7af73000..577c9f475e 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -132,7 +132,7 @@ type lineCountWriter struct { func (l *lineCountWriter) Write(p []byte) (n int, err error) { n = len(p) l.numLines += bytes.Count(p, []byte{'\000'}) - return + return n, err } // GetDiffNumChangedFiles counts the number of changed files @@ -177,7 +177,7 @@ func (repo *Repository) GetDiffShortStat(base, head string) (numFiles, totalAddi if err != nil && strings.Contains(err.Error(), "no merge base") { return GetDiffShortStat(repo.Ctx, repo.Path, base, head) } - return + return numFiles, totalAdditions, totalDeletions, err } // GetDiffShortStat counts number of changed files, number of additions and deletions @@ -231,7 +231,7 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %v", stdout, err) } } - return + return numFiles, totalAdditions, totalDeletions, err } // GetDiffOrPatch generates either diff or formatted patch data between given revisions diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index e163a3090b..245920c2bd 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -117,8 +117,8 @@ func TestReadWritePullHead(t *testing.T) { return } - assert.Len(t, string(headContents), 40) - assert.True(t, string(headContents) == newCommit) + assert.Len(t, headContents, 40) + assert.True(t, headContents == newCommit) // Remove file after the test err = repo.RemoveReference(PullPrefix + "1/head") diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go index ae68dcaa87..50d82c77d7 100644 --- a/modules/git/repo_index.go +++ b/modules/git/repo_index.go @@ -64,7 +64,7 @@ func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpD defer cancel() return "", "", func() {}, err } - return + return filename, tmpDir, cancel, err } // EmptyIndex empties the index diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go index 8d44db0a2e..9a574666f8 100644 --- a/modules/git/repo_tag_nogogit.go +++ b/modules/git/repo_tag_nogogit.go @@ -27,7 +27,7 @@ func (repo *Repository) IsTagExist(name string) bool { // returning at most limit tags, or all if limit is 0. func (repo *Repository) GetTags(skip, limit int) (tags []string, err error) { tags, _, err = callShowRef(repo.Ctx, repo.Path, TagPrefix, "--tags", skip, limit) - return + return tags, err } // GetTagType gets the type of the tag, either commit (simple) or tag (annotated) diff --git a/modules/git/sha1_nogogit.go b/modules/git/sha1_nogogit.go index 1835c68f5a..a2620cba69 100644 --- a/modules/git/sha1_nogogit.go +++ b/modules/git/sha1_nogogit.go @@ -58,5 +58,5 @@ func NewHasher(t ObjectType, size int64) Hasher { // Sum generates a SHA1 for the provided hash func (h Hasher) Sum() (sha1 SHA1) { copy(sha1[:], h.Hash.Sum(nil)) - return + return sha1 } diff --git a/modules/git/signature_nogogit.go b/modules/git/signature_nogogit.go index 81da739a5b..2fc8dde04d 100644 --- a/modules/git/signature_nogogit.go +++ b/modules/git/signature_nogogit.go @@ -91,5 +91,5 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) { return } } - return + return sig, err } diff --git a/modules/git/utils.go b/modules/git/utils.go index 53c124ac8a..d6bf9f4413 100644 --- a/modules/git/utils.go +++ b/modules/git/utils.go @@ -163,7 +163,7 @@ func (l *LimitedReaderCloser) Read(p []byte) (n int, err error) { } n, err = l.R.Read(p) l.N -= int64(n) - return + return n, err } // Close implements io.Closer diff --git a/modules/gitgraph/graph_test.go b/modules/gitgraph/graph_test.go index ea6553529a..2cfbe4b2fa 100644 --- a/modules/gitgraph/graph_test.go +++ b/modules/gitgraph/graph_test.go @@ -53,7 +53,7 @@ func BenchmarkParseGlyphs(b *testing.B) { parser := &Parser{} parser.Reset() tgBytes := []byte(testglyphs) - tg := tgBytes + var tg []byte for i := 0; i < b.N; i++ { parser.Reset() tg = tgBytes diff --git a/modules/graceful/context.go b/modules/graceful/context.go index 9d955329a4..b9d975a1d5 100644 --- a/modules/graceful/context.go +++ b/modules/graceful/context.go @@ -26,7 +26,7 @@ func NewChannelContext(done <-chan struct{}, err error) *ChannelContext { // Deadline returns the time when work done on behalf of this context // should be canceled. There is no Deadline for a ChannelContext func (ctx *ChannelContext) Deadline() (deadline time.Time, ok bool) { - return + return deadline, ok } // Done returns the channel provided at the creation of this context. diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index a72f26d5f0..acd3bebb9f 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -114,7 +114,7 @@ func CodeFromLexer(lexer chroma.Lexer, code string) string { htmlbuf := bytes.Buffer{} htmlw := bufio.NewWriter(&htmlbuf) - iterator, err := lexer.Tokenise(nil, string(code)) + iterator, err := lexer.Tokenise(nil, code) if err != nil { log.Error("Can't tokenize code: %v", err) return code @@ -197,7 +197,7 @@ func File(numLines int, fileName, language string, code []byte) []string { m := make([]string, 0, numLines) for _, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) { - content := string(v) + content := v // need to keep lines that are only \n so copy/paste works properly in browser if content == "" { content = "\n" @@ -220,8 +220,8 @@ func File(numLines int, fileName, language string, code []byte) []string { // return unhiglighted map func plainText(code string, numLines int) []string { m := make([]string, 0, numLines) - for _, v := range strings.SplitN(string(code), "\n", numLines) { - content := string(v) + for _, v := range strings.SplitN(code, "\n", numLines) { + content := v // need to keep lines that are only \n so copy/paste works properly in browser if content == "" { content = "\n" diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go index 1abb3c0219..0b31f7119c 100644 --- a/modules/indexer/code/bleve.go +++ b/modules/indexer/code/bleve.go @@ -392,7 +392,7 @@ func (b *BleveIndexer) Search(ctx context.Context, repoIDs []int64, language, ke searchResults := make([]*SearchResult, len(result.Hits)) for i, hit := range result.Hits { - var startIndex, endIndex int = -1, -1 + startIndex, endIndex := -1, -1 for _, locations := range hit.Locations["Content"] { location := locations[0] locationStart := int(location.Start) diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go index 7263f27657..a669c66bb4 100644 --- a/modules/indexer/code/elastic_search.go +++ b/modules/indexer/code/elastic_search.go @@ -348,7 +348,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int) // FIXME: There is no way to get the position the keyword on the content currently on the same request. // So we get it from content, this may made the query slower. See // https://discuss.elastic.co/t/fetching-position-of-keyword-in-matched-document/94291 - var startIndex, endIndex int = -1, -1 + var startIndex, endIndex int c, ok := hit.Highlight["content"] if ok && len(c) > 0 { // FIXME: Since the highlighting content will include <em> and </em> for the keywords, diff --git a/modules/markup/common/footnote.go b/modules/markup/common/footnote.go index 821b3e6387..d07f5e6090 100644 --- a/modules/markup/common/footnote.go +++ b/modules/markup/common/footnote.go @@ -203,9 +203,8 @@ func (b *footnoteBlockParser) Open(parent ast.Node, reader text.Reader, pc parse return nil, parser.NoChildren } open := pos + 1 - closes := 0 closure := util.FindClosure(line[pos+1:], '[', ']', false, false) //nolint - closes = pos + 1 + closure + closes := pos + 1 + closure next := closes + 1 if closure > -1 { if next >= len(line) || line[next] != ':' { diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index 37e11e606f..4ce85dfc31 100644 --- a/modules/markup/markdown/markdown.go +++ b/modules/markup/markdown/markdown.go @@ -156,7 +156,7 @@ func actualRender(ctx *markup.RenderContext, input io.Reader, output io.Writer) log.Warn("Unable to render markdown due to panic in goldmark: %v", err) if log.IsDebug() { - log.Debug("Panic in markdown: %v\n%s", err, string(log.Stack(2))) + log.Debug("Panic in markdown: %v\n%s", err, log.Stack(2)) } }() @@ -185,7 +185,7 @@ func render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error log.Warn("Unable to render markdown due to panic in goldmark - will return raw bytes") if log.IsDebug() { - log.Debug("Panic in markdown: %v\n%s", err, string(log.Stack(2))) + log.Debug("Panic in markdown: %v\n%s", err, log.Stack(2)) } _, err = io.Copy(output, input) if err != nil { diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 8c9f3b3da7..a78531720d 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -75,7 +75,7 @@ func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error if lexer == nil { // include language-x class as part of commonmark spec - if _, err := w.WriteString(`<code class="chroma language-` + string(lang) + `">`); err != nil { + if _, err := w.WriteString(`<code class="chroma language-` + lang + `">`); err != nil { return "" } if _, err := w.WriteString(html.EscapeString(source)); err != nil { @@ -83,7 +83,7 @@ func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error } } else { // include language-x class as part of commonmark spec - if _, err := w.WriteString(`<code class="chroma language-` + string(lang) + `">`); err != nil { + if _, err := w.WriteString(`<code class="chroma language-` + lang + `">`); err != nil { return "" } lexer = chroma.Coalesce(lexer) diff --git a/modules/markup/sanitizer_test.go b/modules/markup/sanitizer_test.go index a0753c4a56..7dfca7a468 100644 --- a/modules/markup/sanitizer_test.go +++ b/modules/markup/sanitizer_test.go @@ -55,7 +55,7 @@ func Test_Sanitizer(t *testing.T) { func TestSanitizeNonEscape(t *testing.T) { descStr := "<scrİpt><script>alert(document.domain)</script></scrİpt>" - output := template.HTML(Sanitize(string(descStr))) + output := template.HTML(Sanitize(descStr)) if strings.Contains(string(output), "<script>") { t.Errorf("un-escaped <script> in output: %q", output) } diff --git a/modules/migration/issue.go b/modules/migration/issue.go index 78f648dd2d..cc13570afb 100644 --- a/modules/migration/issue.go +++ b/modules/migration/issue.go @@ -30,11 +30,11 @@ type Issue struct { } // GetExternalName ExternalUserMigrated interface -func (i *Issue) GetExternalName() string { return i.PosterName } +func (issue *Issue) GetExternalName() string { return issue.PosterName } // GetExternalID ExternalUserMigrated interface -func (i *Issue) GetExternalID() int64 { return i.PosterID } +func (issue *Issue) GetExternalID() int64 { return issue.PosterID } -func (i *Issue) GetLocalIndex() int64 { return i.Number } -func (i *Issue) GetForeignIndex() int64 { return i.ForeignIndex } -func (i *Issue) GetContext() DownloaderContext { return i.Context } +func (issue *Issue) GetLocalIndex() int64 { return issue.Number } +func (issue *Issue) GetForeignIndex() int64 { return issue.ForeignIndex } +func (issue *Issue) GetContext() DownloaderContext { return issue.Context } diff --git a/modules/nosql/manager.go b/modules/nosql/manager.go index 93338fdc3f..6092a67827 100644 --- a/modules/nosql/manager.go +++ b/modules/nosql/manager.go @@ -75,5 +75,5 @@ func valToTimeDuration(vs []string) (result time.Duration) { return } } - return + return result } diff --git a/modules/nosql/manager_leveldb.go b/modules/nosql/manager_leveldb.go index d69ae88800..d356a79bf8 100644 --- a/modules/nosql/manager_leveldb.go +++ b/modules/nosql/manager_leveldb.go @@ -72,7 +72,7 @@ func (m *Manager) GetLevelDB(connection string) (db *leveldb.DB, err error) { if recovered != nil { panic(recovered) } - return + return db, err } func (m *Manager) getLevelDB(connection string) (*leveldb.DB, error) { diff --git a/modules/nosql/manager_redis.go b/modules/nosql/manager_redis.go index b82f899db0..3b2ad75b41 100644 --- a/modules/nosql/manager_redis.go +++ b/modules/nosql/manager_redis.go @@ -65,7 +65,7 @@ func (m *Manager) GetRedisClient(connection string) (client redis.UniversalClien if recovered != nil { panic(recovered) } - return + return client } func (m *Manager) getRedisClient(connection string) redis.UniversalClient { diff --git a/modules/packages/multi_hasher.go b/modules/packages/multi_hasher.go index 0659a18d2a..4d17441d8c 100644 --- a/modules/packages/multi_hasher.go +++ b/modules/packages/multi_hasher.go @@ -119,5 +119,5 @@ func (h *MultiHasher) Sums() (hashMD5, hashSHA1, hashSHA256, hashSHA512 []byte) hashSHA1 = h.sha1.Sum(nil) hashSHA256 = h.sha256.Sum(nil) hashSHA512 = h.sha512.Sum(nil) - return + return hashMD5, hashSHA1, hashSHA256, hashSHA512 } diff --git a/modules/process/manager.go b/modules/process/manager.go index 5d7aee760f..7f14287de5 100644 --- a/modules/process/manager.go +++ b/modules/process/manager.go @@ -183,7 +183,7 @@ func (pm *Manager) nextPID() (start time.Time, pid IDType) { return } pid = IDType(string(pid) + "-" + strconv.FormatInt(pm.next, 10)) - return + return start, pid } // Remove a process from the ProcessManager. diff --git a/modules/process/manager_stacktraces.go b/modules/process/manager_stacktraces.go index fbe3374b87..628d9cebcd 100644 --- a/modules/process/manager_stacktraces.go +++ b/modules/process/manager_stacktraces.go @@ -120,7 +120,7 @@ func (pm *Manager) ProcessStacktraces(flat, noSystem bool) ([]*Process, int, int // We cannot use the pm.ProcessMap here because we will release the mutex ... processMap := map[IDType]*Process{} - processCount := 0 + var processCount int // Lock the manager pm.mutex.Lock() diff --git a/modules/queue/helper.go b/modules/queue/helper.go index f1aba411a8..9ad95badeb 100644 --- a/modules/queue/helper.go +++ b/modules/queue/helper.go @@ -74,7 +74,7 @@ func unmarshalAs(bs []byte, exemplar interface{}) (data Data, err error) { } else { err = json.Unmarshal(bs, &data) } - return + return data, err } // assignableTo will check if provided data is assignable to the same type as the exemplar diff --git a/modules/queue/queue_bytefifo.go b/modules/queue/queue_bytefifo.go index 99c6428abc..79f69f07ce 100644 --- a/modules/queue/queue_bytefifo.go +++ b/modules/queue/queue_bytefifo.go @@ -73,7 +73,7 @@ func NewByteFIFOQueue(typ Type, byteFIFO ByteFIFO, handle HandlerFunc, cfg, exem failed = append(failed, fail) } } - return + return failed }, config.WorkerPoolConfiguration) return q, nil @@ -401,7 +401,7 @@ func NewByteFIFOUniqueQueue(typ Type, byteFIFO UniqueByteFIFO, handle HandlerFun failed = append(failed, fail) } } - return + return failed }, config.WorkerPoolConfiguration) return q, nil diff --git a/modules/queue/queue_disk_channel.go b/modules/queue/queue_disk_channel.go index 014d93f5b5..c00f620276 100644 --- a/modules/queue/queue_disk_channel.go +++ b/modules/queue/queue_disk_channel.go @@ -62,7 +62,7 @@ func NewPersistableChannelQueue(handle HandlerFunc, cfg, exemplar interface{}) ( failed = append(failed, fail) } } - return + return failed } channelQueue, err := NewChannelQueue(wrappedHandle, ChannelQueueConfiguration{ diff --git a/modules/queue/unique_queue_disk_channel.go b/modules/queue/unique_queue_disk_channel.go index 6ab03094ba..8e0322bb90 100644 --- a/modules/queue/unique_queue_disk_channel.go +++ b/modules/queue/unique_queue_disk_channel.go @@ -62,7 +62,7 @@ func NewPersistableChannelUniqueQueue(handle HandlerFunc, cfg, exemplar interfac failed = append(failed, fail) } } - return + return failed } channelUniqueQueue, err := NewChannelUniqueQueue(wrappedHandle, ChannelUniqueQueueConfiguration{ diff --git a/modules/references/references.go b/modules/references/references.go index 7f5086d093..8fd0c8f055 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -379,7 +379,7 @@ func FindRenderizableReferenceAlphanumeric(content string) (bool, *RenderizableR action, location := findActionKeywords([]byte(content), match[2]) return true, &RenderizableReference{ - Issue: string(content[match[2]:match[3]]), + Issue: content[match[2]:match[3]], RefLocation: &RefSpan{Start: match[2], End: match[3]}, Action: action, ActionLocation: location, @@ -506,7 +506,7 @@ func getCrossReference(content []byte, start, end int, fromLink, prOnly bool) *r } repo := string(content[start : start+sep]) issue := string(content[start+sep+1 : end]) - index, err := strconv.ParseInt(string(issue), 10, 64) + index, err := strconv.ParseInt(issue, 10, 64) if err != nil { return nil } diff --git a/modules/repository/hooks.go b/modules/repository/hooks.go index debaa0ecc4..c2eb3a7c75 100644 --- a/modules/repository/hooks.go +++ b/modules/repository/hooks.go @@ -104,7 +104,7 @@ done giteaHookTpls = append(giteaHookTpls, "") } - return + return hookNames, hookTpls, giteaHookTpls } // CreateDelegateHooks creates all the hooks scripts for the repo diff --git a/modules/setting/database.go b/modules/setting/database.go index a90ace5b4b..87d56fbc93 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -107,7 +107,7 @@ func InitDBConfig() { // DBConnStr returns database connection string func DBConnStr() (string, error) { - connStr := "" + var connStr string Param := "?" if strings.Contains(Database.Name, Param) { Param = "&" @@ -168,7 +168,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbParam, db connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s", url.PathEscape(dbUser), url.PathEscape(dbPasswd), host, port, dbName, dbParam, dbsslMode) } - return + return connStr } // ParseMSSQLHostPort splits the host into host and port diff --git a/modules/setting/federation.go b/modules/setting/federation.go index 2a8ecadaf9..583d9a6e2b 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -31,7 +31,7 @@ var ( } ) -// Constant slice of httpsig algorithm objects +// HttpsigAlgs is a constant slice of httpsig algorithm objects var HttpsigAlgs []httpsig.Algorithm func newFederationService() { diff --git a/modules/setting/i18n.go b/modules/setting/i18n.go index a9a57dc948..321e144ef3 100644 --- a/modules/setting/i18n.go +++ b/modules/setting/i18n.go @@ -40,12 +40,12 @@ func defaultI18nLangs() (res []string) { for i := 0; i < len(defaultI18nLangNames); i += 2 { res = append(res, defaultI18nLangNames[i]) } - return + return res } func defaultI18nNames() (res []string) { for i := 0; i < len(defaultI18nLangNames); i += 2 { res = append(res, defaultI18nLangNames[i+1]) } - return + return res } diff --git a/modules/setting/log.go b/modules/setting/log.go index d69b5c6888..1d9535360a 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -211,7 +211,7 @@ func generateLogConfig(sec *ini.Section, name string, defaults defaultLogOptions return } jsonConfig = string(byteConfig) - return + return mode, jsonConfig, levelName } func generateNamedLogger(key string, options defaultLogOptions) *LogDescription { diff --git a/modules/setting/service.go b/modules/setting/service.go index a391926382..bd97e10b0f 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -96,7 +96,7 @@ func (a AllowedVisibility) ToVisibleTypeSlice() (result []structs.VisibleType) { result = append(result, structs.VisibleType(i)) } } - return + return result } func newService() { diff --git a/modules/storage/storage.go b/modules/storage/storage.go index ef7f6029a5..1b83e3271f 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -169,35 +169,35 @@ func NewStorage(typStr string, cfg interface{}) (ObjectStorage, error) { func initAvatars() (err error) { log.Info("Initialising Avatar storage with type: %s", setting.Avatar.Storage.Type) Avatars, err = NewStorage(setting.Avatar.Storage.Type, &setting.Avatar.Storage) - return + return err } func initAttachments() (err error) { log.Info("Initialising Attachment storage with type: %s", setting.Attachment.Storage.Type) Attachments, err = NewStorage(setting.Attachment.Storage.Type, &setting.Attachment.Storage) - return + return err } func initLFS() (err error) { log.Info("Initialising LFS storage with type: %s", setting.LFS.Storage.Type) LFS, err = NewStorage(setting.LFS.Storage.Type, &setting.LFS.Storage) - return + return err } func initRepoAvatars() (err error) { log.Info("Initialising Repository Avatar storage with type: %s", setting.RepoAvatar.Storage.Type) RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, &setting.RepoAvatar.Storage) - return + return err } func initRepoArchives() (err error) { log.Info("Initialising Repository Archive storage with type: %s", setting.RepoArchive.Storage.Type) RepoArchives, err = NewStorage(setting.RepoArchive.Storage.Type, &setting.RepoArchive.Storage) - return + return err } func initPackages() (err error) { log.Info("Initialising Packages storage with type: %s", setting.Packages.Storage.Type) Packages, err = NewStorage(setting.Packages.Storage.Type, &setting.Packages.Storage) - return + return err } diff --git a/modules/structs/org_type.go b/modules/structs/org_type.go index 4fb9b6fc0f..4401a2801c 100644 --- a/modules/structs/org_type.go +++ b/modules/structs/org_type.go @@ -55,5 +55,5 @@ func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { for k := range in { keys = append(keys, k) } - return + return keys } diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 99b1979964..93463ce0c2 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -733,7 +733,7 @@ func RenderCommitMessageLink(ctx context.Context, msg, urlPrefix, urlDefault str log.Error("RenderCommitMessage: %v", err) return "" } - msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n") + msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") if len(msgLines) == 0 { return template.HTML("") } @@ -843,7 +843,7 @@ func RenderNote(ctx context.Context, msg, urlPrefix string, metas map[string]str log.Error("RenderNote: %v", err) return "" } - return template.HTML(string(fullMessage)) + return template.HTML(fullMessage) } // IsMultilineCommitMessage checks to see if a commit message contains multiple lines. diff --git a/modules/templates/helper_test.go b/modules/templates/helper_test.go index e2997cb853..5ebae7afef 100644 --- a/modules/templates/helper_test.go +++ b/modules/templates/helper_test.go @@ -17,8 +17,8 @@ func TestSubjectBodySeparator(t *testing.T) { assert.Empty(t, subject, "no subject found, but one expected") assert.Equal(t, body, input) } else { - assert.Equal(t, subject, string(input[0:loc[0]])) - assert.Equal(t, body, string(input[loc[1]:])) + assert.Equal(t, subject, input[0:loc[0]]) + assert.Equal(t, body, input[loc[1]:]) } } diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index 38b12829ad..b22fe59ba2 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -30,7 +30,7 @@ func round(s float64) int64 { } func computeTimeDiffFloor(diff int64, lang string) (int64, string) { - diffStr := "" + var diffStr string switch { case diff <= 0: diff = 0 @@ -88,7 +88,7 @@ func computeTimeDiffFloor(diff int64, lang string) (int64, string) { } func computeTimeDiff(diff int64, lang string) (int64, string) { - diffStr := "" + var diffStr string switch { case diff <= 0: diff = 0 diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go index 1fe8d4fcb1..88008d1fad 100644 --- a/modules/timeutil/timestamp.go +++ b/modules/timeutil/timestamp.go @@ -57,7 +57,7 @@ func (ts TimeStamp) AsTime() (tm time.Time) { // AsTimeInLocation convert timestamp as time.Time in Local locale func (ts TimeStamp) AsTimeInLocation(loc *time.Location) (tm time.Time) { tm = time.Unix(int64(ts), 0).In(loc) - return + return tm } // AsTimePtr convert timestamp as *time.Time in Local locale diff --git a/modules/util/io.go b/modules/util/io.go index 0c677c359f..d765e27733 100644 --- a/modules/util/io.go +++ b/modules/util/io.go @@ -16,5 +16,5 @@ func ReadAtMost(r io.Reader, buf []byte) (n int, err error) { if err == io.EOF || err == io.ErrUnexpectedEOF { err = nil } - return + return n, err } diff --git a/modules/web/wrap_convert.go b/modules/web/wrap_convert.go index b7bcbc6439..9084cfa074 100644 --- a/modules/web/wrap_convert.go +++ b/modules/web/wrap_convert.go @@ -28,7 +28,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 { done = true } - return + return done, deferrable } case func(http.ResponseWriter, *http.Request): return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -37,7 +37,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 { done = true } - return + return done, deferrable } case func(ctx *context.Context): @@ -46,7 +46,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetContext(req) t(ctx) done = ctx.Written() - return + return done, deferrable } case func(ctx *context.Context) goctx.CancelFunc: return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -54,7 +54,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetContext(req) deferrable = t(ctx) done = ctx.Written() - return + return done, deferrable } case func(*context.APIContext): return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -62,7 +62,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetAPIContext(req) t(ctx) done = ctx.Written() - return + return done, deferrable } case func(*context.APIContext) goctx.CancelFunc: return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -70,7 +70,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetAPIContext(req) deferrable = t(ctx) done = ctx.Written() - return + return done, deferrable } case func(*context.PrivateContext): return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -78,7 +78,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetPrivateContext(req) t(ctx) done = ctx.Written() - return + return done, deferrable } case func(*context.PrivateContext) goctx.CancelFunc: return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -86,7 +86,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { ctx := context.GetPrivateContext(req) deferrable = t(ctx) done = ctx.Written() - return + return done, deferrable } case func(http.Handler) http.Handler: return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) { @@ -102,7 +102,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc { if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 { done = true } - return + return done, deferrable } default: panic(fmt.Sprintf("Unsupported handler type: %#v", t)) |