Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
4f0be128
Commit
4f0be128
authored
1 year ago
by
Pavel Antonov
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Изменена реализация action.URL
parent
57517bc5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/action/action.go
+15
-52
15 additions, 52 deletions
pkg/action/action.go
with
15 additions
and
52 deletions
pkg/action/action.go
+
15
−
52
View file @
4f0be128
package
action
import
(
"fmt"
"net/url"
"strings"
"git.perx.ru/perxis/perxis-go/pkg/errors"
)
// URL структура для хранения данных о переданном действии.
type
URL
struct
{
*
url
.
URL
id
string
extension
string
}
// NewURL возвращает структуру ActionURL
func
NewURL
(
action
string
)
(
*
URL
,
error
)
{
actionURL
:=
new
(
URL
)
if
action
==
""
{
return
actionURL
,
nil
}
err
:=
actionURL
.
SetURL
(
action
)
u
,
err
:=
url
.
Parse
(
action
)
if
err
!=
nil
{
return
nil
,
err
}
if
actionURL
.
URL
.
Scheme
==
"grpc"
{
splitPath
:=
strings
.
Split
(
strings
.
TrimLeft
(
actionURL
.
Path
,
"/"
),
"/"
)
if
len
(
splitPath
)
<
2
{
return
nil
,
errors
.
Errorf
(
"incorrect action URL, no action id: '%s'"
,
action
)
}
actionURL
.
extension
=
splitPath
[
0
]
actionURL
.
id
=
splitPath
[
1
]
}
return
actionURL
,
nil
return
&
URL
{
URL
:
u
},
nil
}
// ID возвращает сохраненный в URL id действия
func
(
u
*
URL
)
ID
()
string
{
return
u
.
id
func
(
u
*
URL
)
actionParts
()
(
string
,
string
)
{
if
u
.
URL
==
nil
&&
u
.
URL
.
Scheme
==
"grpc"
{
splitPath
:=
strings
.
Split
(
strings
.
TrimLeft
(
u
.
Path
,
"/"
),
"/"
)
if
len
(
splitPath
)
>=
2
{
return
splitPath
[
0
],
splitPath
[
1
]
}
}
return
""
,
""
}
// SetID устанавливает в URL id действия
func
(
u
*
URL
)
SetID
(
id
string
)
{
u
.
id
=
id
func
(
u
*
URL
)
Action
()
string
{
_
,
action
:=
u
.
actionParts
()
return
action
}
// Extension возвращает сохраненный в URL id расширения
func
(
u
*
URL
)
Extension
()
string
{
return
u
.
extension
}
// SetExtension устанавливает в URL id расширения
func
(
u
*
URL
)
SetExtension
(
ext
string
)
{
u
.
extension
=
ext
}
// SetURL устанавливает структуру URL
func
(
u
*
URL
)
SetURL
(
s
string
)
(
err
error
)
{
if
u
.
URL
,
err
=
url
.
Parse
(
s
);
err
!=
nil
{
return
err
}
return
nil
}
// MakeURL возвращает Action URL из сохраненных данных
func
(
u
*
URL
)
String
()
string
{
if
u
.
id
!=
""
&&
u
.
extension
!=
""
{
return
fmt
.
Sprintf
(
"grpc:///%s/%s"
,
u
.
extension
,
u
.
id
)
}
return
u
.
URL
.
String
()
ext
,
_
:=
u
.
actionParts
()
return
ext
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment