Skip to content

Commit 76f0a46

Browse files
refactor: use strings.Cut to simplify code (#22590)
Signed-off-by: liuyueyangxmu <liuyueyangxmu@outlook.com>
1 parent 0c3f6c7 commit 76f0a46

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/common/utils/utils.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ func ParseRepository(repository string) (project, rest string) {
6060
rest = repository
6161
return
6262
}
63-
index := strings.Index(repository, "/")
64-
project = repository[0:index]
65-
rest = repository[index+1:]
63+
project, rest, _ = strings.Cut(repository, "/")
6664
return
6765
}
6866

src/controller/event/handler/util/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func SendHookWithPolicies(ctx context.Context, policies []*policy_model.Policy,
6969

7070
// GetNameFromImgRepoFullName gets image name from repo full name with format `repoName/imageName`
7171
func GetNameFromImgRepoFullName(repo string) string {
72-
idx := strings.Index(repo, "/")
73-
return repo[idx+1:]
72+
_, after, _ := strings.Cut(repo, "/")
73+
return after
7474
}
7575

7676
// BuildImageResourceURL ...

0 commit comments

Comments
 (0)