3
0

upd(codegen): delete sam symlink

This commit is contained in:
Tit Petric
2018-08-15 17:40:16 +02:00
parent 92484d6ba4
commit 60264dfcab
3 changed files with 77 additions and 1 deletions
-1
View File
@@ -1 +0,0 @@
crm
+31
View File
@@ -0,0 +1,31 @@
<?php
foreach ($apis as $api) {
if (is_array($api['struct'])) {
$name = ucfirst($api['interface']);
$filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go");
$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();
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";
}
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
$templates = array(
"http_interfaces.tpl" => function($name, $api) {
return strtolower($name) . ".go";
},
"http_request.tpl" => function($name, $api) {
return strtolower($name) . "_requests.go";
},
"http_handlers.tpl" => function($name, $api) {
return strtolower($name) . "_handlers.go";
},
"http_routes.tpl" => function($name, $api) {
return strtolower($name) . "_routes.go";
}
);
foreach ($templates as $template => $fn)
foreach ($apis as $api) {
if (is_array($api['struct'])) {
$name = ucfirst($api['interface']);
$filename = $dirname . "/" . $fn($name, $api);
$tpl->load($template);
$tpl->assign($common);
$tpl->assign("package", basename(__DIR__));
$tpl->assign("name", $name);
$tpl->assign("api", $api);
$tpl->assign("apis", $apis);
$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());
file_put_contents($filename, $contents);
echo $filename . "\n";
}
}