From d6d2c545daca1c852307c3a9fd7eaa543910f4d4 Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Thu, 21 Sep 2023 13:35:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20action?= =?UTF-8?q?=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/extension/extension.go | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/extension/extension.go b/pkg/extension/extension.go index fb8044c7..5277dd50 100644 --- a/pkg/extension/extension.go +++ b/pkg/extension/extension.go @@ -3,6 +3,8 @@ package extension import ( "context" "fmt" + "net/url" + "strings" "git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/errors" @@ -105,3 +107,46 @@ func ExtensionFromError(err error) string { ext, _ := v.(string) return ext } + +type ParsedActionURL struct { + actionID string + extensionID string + scheme string +} + +func (p *ParsedActionURL) New() *ParsedActionURL { + return &ParsedActionURL{} +} + +func (p *ParsedActionURL) GetActionID() string { + return p.actionID +} + +func (p *ParsedActionURL) GetExtensionID() string { + return p.extensionID +} + +func (p *ParsedActionURL) GetScheme() string { + return p.scheme +} + +func (p *ParsedActionURL) Parse(action string) error { + u, err := url.Parse(action) + if err != nil { + return err + } + p.scheme = u.Scheme + if p.GetScheme() == "grpc" { + path := u.Path + if strings.HasPrefix(u.Path, "/") { + path = u.Path[1:] + } + splitPath := strings.Split(path, "/") + if len(splitPath) < 2 { + return errors.Errorf("incorrect action URL, no action id: '%s'", action) + } + p.extensionID = splitPath[0] + p.actionID = splitPath[1] + } + return nil +} -- GitLab