From af5541af486dc15866544b00ed5f502b7ba51faa Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 27 Nov 2023 10:24:01 +0800 Subject: [PATCH] feat: support ws/wss Signed-off-by: rfyiamcool --- shortuuid.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shortuuid.go b/shortuuid.go index 7ae1ef5..36bf3d6 100644 --- a/shortuuid.go +++ b/shortuuid.go @@ -33,10 +33,19 @@ func NewWithNamespace(name string) string { switch { case name == "": u = uuid.New() + case strings.HasPrefix(strings.ToLower(name), "http://"): u = uuid.NewSHA1(uuid.NameSpaceURL, []byte(name)) + case strings.HasPrefix(strings.ToLower(name), "https://"): u = uuid.NewSHA1(uuid.NameSpaceURL, []byte(name)) + + case strings.HasPrefix(strings.ToLower(name), "ws://"): + u = uuid.NewSHA1(uuid.NameSpaceURL, []byte(name)) + + case strings.HasPrefix(strings.ToLower(name), "wss://"): + u = uuid.NewSHA1(uuid.NameSpaceURL, []byte(name)) + default: u = uuid.NewSHA1(uuid.NameSpaceDNS, []byte(name)) }