mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
cmd/go/internal: use the newly added strings.CutSuffix method to optimize the code
Signed-off-by: cui fliter <imcusg@gmail.com>
This commit is contained in:
parent
c2ede92a0d
commit
a87597d8a7
|
@ -340,16 +340,14 @@ func clean(p *load.Package) {
|
|||
continue
|
||||
}
|
||||
|
||||
if strings.HasSuffix(name, "_test.go") {
|
||||
base := name[:len(name)-len("_test.go")]
|
||||
if base, found := strings.CutSuffix(name, "_test.go"); found {
|
||||
allRemove = append(allRemove, base+".test", base+".test.exe")
|
||||
}
|
||||
|
||||
if strings.HasSuffix(name, ".go") {
|
||||
if base, found := strings.CutSuffix(name, ".go"); found {
|
||||
// TODO(adg,rsc): check that this .go file is actually
|
||||
// in "package main", and therefore capable of building
|
||||
// to an executable file.
|
||||
base := name[:len(name)-len(".go")]
|
||||
allRemove = append(allRemove, base, base+".exe")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3115,10 +3115,10 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
|
|||
}
|
||||
patterns := make([]string, len(args))
|
||||
for i, arg := range args {
|
||||
if !strings.HasSuffix(arg, "@"+version) {
|
||||
p, found := strings.CutSuffix(arg, "@"+version)
|
||||
if !found {
|
||||
return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version)
|
||||
}
|
||||
p := arg[:len(arg)-len(version)-1]
|
||||
switch {
|
||||
case build.IsLocalImport(p):
|
||||
return nil, fmt.Errorf("%s: argument must be a package path, not a relative path", arg)
|
||||
|
|
Loading…
Reference in a new issue