From 30d12b4041a463f8a04d365fc1a2d62784f3b3dd Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 4 Sep 2018 15:38:05 +0200 Subject: [PATCH] upd(codegen): update some basic templates --- codegen/crm/rest/index.php | 47 ++++++++++++++++++------------------- codegen/sam/rest/index.php | 47 ++++++++++++++++++------------------- codegen/templates/http_.tpl | 4 ++-- 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/codegen/crm/rest/index.php b/codegen/crm/rest/index.php index 4869b8b54..fc5eabcd9 100644 --- a/codegen/crm/rest/index.php +++ b/codegen/crm/rest/index.php @@ -1,31 +1,30 @@ load("http_.tpl"); - $tpl->assign($common); - $tpl->assign("package", basename(__DIR__)); - $tpl->assign("name", $name); - $tpl->assign("api", $api); - $tpl->assign("self", strtolower(substr($name, 0, 1))); - $tpl->assign("structs", $api['struct']); - $imports = array(); - foreach ($api['struct'] as $struct) { - if (isset($struct['imports'])) - foreach ($struct['imports'] as $import) { - $imports[] = $import; - } - } - $tpl->assign("imports", $imports); - $tpl->assign("calls", $api['apis']); - $contents = str_replace("\n\n}", "\n}", $tpl->get()); - - if (!file_exists($filename)) { - file_put_contents($filename, $contents); - echo $filename . "\n"; + $tpl->load("http_.tpl"); + $tpl->assign($common); + $tpl->assign("package", basename(__DIR__)); + $tpl->assign("name", $name); + $tpl->assign("api", $api); + $tpl->assign("self", strtolower(substr($name, 0, 1))); + $tpl->assign("structs", $api['struct']); + $imports = array(); + if (is_array($api['struct'])) + foreach ($api['struct'] as $struct) { + if (isset($struct['imports'])) + foreach ($struct['imports'] as $import) { + $imports[] = $import; } } + $tpl->assign("imports", $imports); + $tpl->assign("calls", $api['apis']); + $contents = str_replace("\n\n}", "\n}", $tpl->get()); + + if (!file_exists($filename)) { + file_put_contents($filename, $contents); + echo $filename . "\n"; + } } diff --git a/codegen/sam/rest/index.php b/codegen/sam/rest/index.php index 4869b8b54..fc5eabcd9 100644 --- a/codegen/sam/rest/index.php +++ b/codegen/sam/rest/index.php @@ -1,31 +1,30 @@ load("http_.tpl"); - $tpl->assign($common); - $tpl->assign("package", basename(__DIR__)); - $tpl->assign("name", $name); - $tpl->assign("api", $api); - $tpl->assign("self", strtolower(substr($name, 0, 1))); - $tpl->assign("structs", $api['struct']); - $imports = array(); - foreach ($api['struct'] as $struct) { - if (isset($struct['imports'])) - foreach ($struct['imports'] as $import) { - $imports[] = $import; - } - } - $tpl->assign("imports", $imports); - $tpl->assign("calls", $api['apis']); - $contents = str_replace("\n\n}", "\n}", $tpl->get()); - - if (!file_exists($filename)) { - file_put_contents($filename, $contents); - echo $filename . "\n"; + $tpl->load("http_.tpl"); + $tpl->assign($common); + $tpl->assign("package", basename(__DIR__)); + $tpl->assign("name", $name); + $tpl->assign("api", $api); + $tpl->assign("self", strtolower(substr($name, 0, 1))); + $tpl->assign("structs", $api['struct']); + $imports = array(); + if (is_array($api['struct'])) + foreach ($api['struct'] as $struct) { + if (isset($struct['imports'])) + foreach ($struct['imports'] as $import) { + $imports[] = $import; } } + $tpl->assign("imports", $imports); + $tpl->assign("calls", $api['apis']); + $contents = str_replace("\n\n}", "\n}", $tpl->get()); + + if (!file_exists($filename)) { + file_put_contents($filename, $contents); + echo $filename . "\n"; + } } diff --git a/codegen/templates/http_.tpl b/codegen/templates/http_.tpl index 9bac57c9b..c02cbe3b6 100644 --- a/codegen/templates/http_.tpl +++ b/codegen/templates/http_.tpl @@ -2,7 +2,7 @@ package {package} import ( "context" - "github.com/crusttech/crust/{project}/rest/server" + "github.com/crusttech/crust/{project}/rest/request" "github.com/pkg/errors" ) @@ -15,7 +15,7 @@ func ({name}) New() *{name} { } {foreach $calls as $call} -func (ctrl *{name}) {call.name|capitalize}(ctx context.Context, r *server.{name|ucfirst}{call.name|capitalize}Request) (interface{}, error) { +func (ctrl *{name}) {call.name|capitalize}(ctx context.Context, r *request.{name|ucfirst}{call.name|capitalize}) (interface{}, error) { return nil, errors.New("Not implemented: {name}.{call.name}") }