Skip to content
Snippets Groups Projects
Commit d6d2c545 authored by ko_oler's avatar ko_oler
Browse files

Выделена отдельная структура и методы для работы с action URL

parent 30b5e866
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment