3
0

upd(codegen): update some basic templates

This commit is contained in:
Tit Petric 2018-09-04 15:38:05 +02:00
parent bdb0844a48
commit 30d12b4041
3 changed files with 48 additions and 50 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
foreach ($apis as $api) { foreach ($apis as $api) {
if (is_array($api['struct'])) {
$name = ucfirst($api['interface']); $name = ucfirst($api['interface']);
$filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go"); $filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go");
@ -13,6 +12,7 @@ foreach ($apis as $api) {
$tpl->assign("self", strtolower(substr($name, 0, 1))); $tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']); $tpl->assign("structs", $api['struct']);
$imports = array(); $imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) { foreach ($api['struct'] as $struct) {
if (isset($struct['imports'])) if (isset($struct['imports']))
foreach ($struct['imports'] as $import) { foreach ($struct['imports'] as $import) {
@ -27,5 +27,4 @@ foreach ($apis as $api) {
file_put_contents($filename, $contents); file_put_contents($filename, $contents);
echo $filename . "\n"; echo $filename . "\n";
} }
}
} }

View File

@ -1,7 +1,6 @@
<?php <?php
foreach ($apis as $api) { foreach ($apis as $api) {
if (is_array($api['struct'])) {
$name = ucfirst($api['interface']); $name = ucfirst($api['interface']);
$filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go"); $filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go");
@ -13,6 +12,7 @@ foreach ($apis as $api) {
$tpl->assign("self", strtolower(substr($name, 0, 1))); $tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']); $tpl->assign("structs", $api['struct']);
$imports = array(); $imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) { foreach ($api['struct'] as $struct) {
if (isset($struct['imports'])) if (isset($struct['imports']))
foreach ($struct['imports'] as $import) { foreach ($struct['imports'] as $import) {
@ -27,5 +27,4 @@ foreach ($apis as $api) {
file_put_contents($filename, $contents); file_put_contents($filename, $contents);
echo $filename . "\n"; echo $filename . "\n";
} }
}
} }

View File

@ -2,7 +2,7 @@ package {package}
import ( import (
"context" "context"
"github.com/crusttech/crust/{project}/rest/server" "github.com/crusttech/crust/{project}/rest/request"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -15,7 +15,7 @@ func ({name}) New() *{name} {
} }
{foreach $calls as $call} {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}") return nil, errors.New("Not implemented: {name}.{call.name}")
} }