upd(codegen): re-add minimal type generation
This commit is contained in:
37
codegen/crm/types/index.php
Normal file
37
codegen/crm/types/index.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
$templates = array(
|
||||
"http_structs.tpl" => function($name, $api) {
|
||||
return strtolower($name) . ".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";
|
||||
}
|
||||
}
|
||||
25
codegen/templates/http_structs.tpl
Normal file
25
codegen/templates/http_structs.tpl
Normal file
@@ -0,0 +1,25 @@
|
||||
package {package}
|
||||
|
||||
{load warning_short.tpl}
|
||||
|
||||
{if !empty($imports)}
|
||||
import (
|
||||
{foreach ($imports as $import)}
|
||||
"{import}"
|
||||
{/foreach}
|
||||
)
|
||||
{/if}
|
||||
|
||||
{if !empty($structs)}
|
||||
type (
|
||||
{foreach $structs as $struct}
|
||||
// {api.title} - {api.description}
|
||||
{struct.name} struct {
|
||||
{foreach $struct.fields as $field}
|
||||
{field.name} {field.type} `{if $field.tag}{$field.tag} {/if}db:"{if $field.db}{$field.db}{else}{$field.name|decamel}{/if}"`{newline}
|
||||
{/foreach}
|
||||
}
|
||||
|
||||
{/foreach}
|
||||
)
|
||||
{/if}
|
||||
1
codegen/templates/warning_short.tpl
Normal file
1
codegen/templates/warning_short.tpl
Normal file
@@ -0,0 +1 @@
|
||||
/* If you want to edit this file by hand, remove codegen/[project]/types/index.php */
|
||||
Reference in New Issue
Block a user