mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11 Reviewed-on: https://go-review.googlesource.com/c/go/+/435138 Run-TryBot: xie cui <523516579@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
bc73996fac
commit
7f7f27f992
|
@ -710,8 +710,7 @@ func rewriteVersionList(dir string) (err error) {
|
|||
// involved in module graph construction, many *.zip files
|
||||
// will never be requested.
|
||||
name := info.Name()
|
||||
if strings.HasSuffix(name, ".mod") {
|
||||
v := strings.TrimSuffix(name, ".mod")
|
||||
if v, found := strings.CutSuffix(name, ".mod"); found {
|
||||
if v != "" && module.CanonicalVersion(v) == v {
|
||||
list = append(list, v)
|
||||
}
|
||||
|
|
|
@ -262,8 +262,8 @@ func (r *gitRepo) loadRefs() (map[string]string, error) {
|
|||
}
|
||||
}
|
||||
for ref, hash := range refs {
|
||||
if strings.HasSuffix(ref, "^{}") { // record unwrapped annotated tag as value of tag
|
||||
refs[strings.TrimSuffix(ref, "^{}")] = hash
|
||||
if k, found := strings.CutSuffix(ref, "^{}"); found { // record unwrapped annotated tag as value of tag
|
||||
refs[k] = hash
|
||||
delete(refs, ref)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -698,9 +698,9 @@ func addModSumLocked(mod module.Version, h string) {
|
|||
func checkSumDB(mod module.Version, h string) error {
|
||||
modWithoutSuffix := mod
|
||||
noun := "module"
|
||||
if strings.HasSuffix(mod.Version, "/go.mod") {
|
||||
if before, found := strings.CutSuffix(mod.Version, "/go.mod"); found {
|
||||
noun = "go.mod"
|
||||
modWithoutSuffix.Version = strings.TrimSuffix(mod.Version, "/go.mod")
|
||||
modWithoutSuffix.Version = before
|
||||
}
|
||||
|
||||
db, lines, err := lookupSumDB(mod)
|
||||
|
|
|
@ -642,12 +642,12 @@ OverlayLoop:
|
|||
var sourceFile string
|
||||
var coverFile string
|
||||
var key string
|
||||
if strings.HasSuffix(file, ".cgo1.go") {
|
||||
if base, found := strings.CutSuffix(file, ".cgo1.go"); found {
|
||||
// cgo files have absolute paths
|
||||
base := filepath.Base(file)
|
||||
base = filepath.Base(base)
|
||||
sourceFile = file
|
||||
coverFile = objdir + base
|
||||
key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
|
||||
coverFile = objdir + base + ".cgo1.go"
|
||||
key = base + ".go"
|
||||
} else {
|
||||
sourceFile = filepath.Join(p.Dir, file)
|
||||
coverFile = objdir + file
|
||||
|
|
Loading…
Reference in a new issue