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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
365a89ae
Commit
365a89ae
authored
4 months ago
by
Semyon Krestyaninov
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
91dd9d5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/schema/executor/template_executor.go
+10
-9
10 additions, 9 deletions
pkg/schema/executor/template_executor.go
with
10 additions
and
9 deletions
pkg/schema/executor/template_executor.go
+
10
−
9
View file @
365a89ae
...
...
@@ -9,24 +9,25 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/errors"
)
// TemplateExecutor выполняет шаблоны, используя заданные данные.
type
TemplateExecutor
struct
{
env
map
[
string
]
any
data
map
[
string
]
any
funcMap
template
.
FuncMap
}
func
NewTemplateExecutor
(
env
map
[
string
]
any
)
*
TemplateExecutor
{
func
NewTemplateExecutor
(
data
map
[
string
]
any
)
*
TemplateExecutor
{
te
:=
&
TemplateExecutor
{
env
:
env
,
data
:
data
,
}
te
.
init
()
return
te
}
func
(
exec
*
TemplateExecutor
)
init
()
{
if
exec
.
env
==
nil
{
exec
.
env
=
make
(
map
[
string
]
any
)
if
exec
.
data
==
nil
{
exec
.
data
=
make
(
map
[
string
]
any
)
}
delete
(
exec
.
env
,
"Error"
)
delete
(
exec
.
data
,
"Error"
)
exec
.
funcMap
=
template
.
FuncMap
{
"error"
:
exec
.
errorFunc
,
...
...
@@ -42,7 +43,7 @@ func (exec *TemplateExecutor) Execute(_ context.Context, input string) (string,
buf
:=
getBuffer
()
defer
releaseBuffer
(
buf
)
err
=
templ
.
Execute
(
buf
,
exec
.
env
)
err
=
templ
.
Execute
(
buf
,
exec
.
data
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -56,12 +57,12 @@ func (exec *TemplateExecutor) Execute(_ context.Context, input string) (string,
}
func
(
exec
*
TemplateExecutor
)
IsCanceled
()
bool
{
_
,
ok
:=
exec
.
env
[
"Error"
]
_
,
ok
:=
exec
.
data
[
"Error"
]
return
ok
}
func
(
exec
*
TemplateExecutor
)
errorFunc
(
text
string
)
(
string
,
error
)
{
exec
.
env
[
"Error"
]
=
text
exec
.
data
[
"Error"
]
=
text
return
""
,
errors
.
New
(
text
)
}
...
...
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