From 9253c44ba5c0838c2d1c00f1728da1e77e3c4ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 13 Nov 2023 18:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8utils.CutPrefix=E4=BB=A3?= =?UTF-8?q?=E6=9B=BFstrings.CutPrefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/node_tasks.go | 3 ++- internal/utils/string.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/nodes/node_tasks.go b/internal/nodes/node_tasks.go index 2fdfab5..09c13ed 100644 --- a/internal/nodes/node_tasks.go +++ b/internal/nodes/node_tasks.go @@ -17,6 +17,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/TeaOSLab/EdgeNode/internal/trackers" + "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/waf" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/maps" @@ -298,7 +299,7 @@ func (this *Node) execUpdatingServersTask(rpcClient *rpc.RPCClient) error { // 删除IP名单 func (this *Node) execDeleteIPList(taskType string) error { - optionsString, ok := strings.CutPrefix(taskType, "ipListDeleted@") + optionsString, ok := utils.CutPrefix(taskType, "ipListDeleted@") if !ok { return errors.New("invalid task type '" + taskType + "'") } diff --git a/internal/utils/string.go b/internal/utils/string.go index dc3745c..4026a98 100644 --- a/internal/utils/string.go +++ b/internal/utils/string.go @@ -56,3 +56,16 @@ func EqualStrings(s1 []string, s2 []string) bool { } return true } + +// CutPrefix returns s without the provided leading prefix string +// and reports whether it found the prefix. +// If s doesn't start with prefix, CutPrefix returns s, false. +// If prefix is the empty string, CutPrefix returns s, true. +// +// copy from go source +func CutPrefix(s, prefix string) (after string, found bool) { + if !strings.HasPrefix(s, prefix) { + return s, false + } + return s[len(prefix):], true +}