mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 23:03:48 +00:00
chore: misc go 1.27 tweaks (#39069)
Follow-up to https://github.com/go-gitea/gitea/pull/39068, which disabled `modernize` entirely. - re-enable `modernize`, with only the new `embedlit` rule disabled. It flattens embedded struct literals across ~145 files, and orphans imports in 6 of them that the fixer does not remove - apply the rest of the suite: `errors.AsType`, `reflect.TypeAssert`, `strings.Cut`, and dropping the legacy import comment - use the new stdlib `uuid` package, `github.com/google/uuid` becomes indirect - use `strings.CutLast` in place of manual `LastIndex` slicing in label scopes, email domains and the diff tree list - take the header lint skip dirs from the `go.mod` `ignore` directive and skip dot-directories, instead of hardcoding the list Assisted-by: Claude Code:claude-opus-5
This commit is contained in:
@@ -16,11 +16,11 @@ import (
|
||||
|
||||
// LookupFederatedHost returns the avatar host from the email domain's SRV record. https://wiki.libravatar.org/api/
|
||||
func LookupFederatedHost(ctx context.Context, email string, secure bool) string {
|
||||
at := strings.LastIndexByte(email, '@')
|
||||
if at < 0 {
|
||||
_, domain, found := strings.CutLast(email, "@")
|
||||
if !found {
|
||||
return ""
|
||||
}
|
||||
domain := strings.ToLower(email[at+1:])
|
||||
domain = strings.ToLower(domain)
|
||||
|
||||
service, defaultPort := "avatars", uint16(80)
|
||||
if secure {
|
||||
|
||||
@@ -114,8 +114,7 @@ func (c *Commit) HasPreviousCommit(ctx context.Context, gitRepo *Repository, obj
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
var exitError *exec.ExitError
|
||||
if errors.As(err, &exitError) {
|
||||
if exitError, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
if exitError.ProcessState.ExitCode() == 1 && len(exitError.Stderr) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ func asLogStringer(v any) LogStringer {
|
||||
// in case the receiver is a pointer, but the value is a struct
|
||||
vp := reflect.New(a.Type())
|
||||
vp.Elem().Set(a)
|
||||
if s, ok := vp.Interface().(LogStringer); ok {
|
||||
if s, ok := reflect.TypeAssert[LogStringer](vp); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func loadActionsFrom(rootCfg ConfigProvider) error {
|
||||
}
|
||||
|
||||
if urls := string(Actions.DefaultActionsURL); urls != defaultActionsURLGitHub && urls != defaultActionsURLSelf {
|
||||
url := strings.Split(urls, ",")[0]
|
||||
url, _, _ := strings.Cut(urls, ",")
|
||||
if strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://") {
|
||||
log.Error("[actions] DEFAULT_ACTIONS_URL does not support %q as custom URL any longer, fallback to %q",
|
||||
urls,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs // import "gitea.dev/modules/structs"
|
||||
package structs
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -99,8 +99,7 @@ func ErrorWrapTranslatable(err error, trKey string, trArgs ...any) ErrorTranslat
|
||||
}
|
||||
|
||||
func ErrorAsTranslatable(err error) ErrorTranslatable {
|
||||
var e *errorTranslatableWrapper
|
||||
if errors.As(err, &e) {
|
||||
if e, ok := errors.AsType[*errorTranslatableWrapper](err); ok {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -64,12 +64,12 @@ func IsEmailDomainListed(globs []glob.Glob, email string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
n := strings.LastIndex(email, "@")
|
||||
if n <= 0 {
|
||||
localPart, domain, found := strings.CutLast(email, "@")
|
||||
if !found || localPart == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
domain := strings.ToLower(email[n+1:])
|
||||
domain = strings.ToLower(domain)
|
||||
|
||||
for _, g := range globs {
|
||||
if g.Match(domain) {
|
||||
|
||||
@@ -66,7 +66,7 @@ var (
|
||||
func preCheckHandler(fn reflect.Value, argsIn []reflect.Value) {
|
||||
hasStatusProvider := false
|
||||
for _, argIn := range argsIn {
|
||||
if _, hasStatusProvider = argIn.Interface().(types.ResponseStatusProvider); hasStatusProvider {
|
||||
if _, hasStatusProvider = reflect.TypeAssert[types.ResponseStatusProvider](argIn); hasStatusProvider {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func handleResponse(fn reflect.Value, ret []reflect.Value) {
|
||||
|
||||
func hasResponseBeenWritten(argsIn []reflect.Value) bool {
|
||||
for _, argIn := range argsIn {
|
||||
if statusProvider, ok := argIn.Interface().(types.ResponseStatusProvider); ok {
|
||||
if statusProvider, ok := reflect.TypeAssert[types.ResponseStatusProvider](argIn); ok {
|
||||
if statusProvider.WrittenStatus() != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user