3
0

Types structs reduced & simplified

This commit is contained in:
Denis Arh
2018-07-29 16:37:41 +02:00
parent a5df66e5e1
commit 5a347dddb5
46 changed files with 263 additions and 1519 deletions
-29
View File
@@ -1,29 +0,0 @@
<?php
foreach ($apis as $api) {
if (is_array($api['struct'])) {
$name = ucfirst($api['interface']);
$filename = $dirname . "/" . str_replace("..", ".", strtolower($name) . ".go");
$tpl->load("http_structs.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());
file_put_contents($filename, $contents);
echo $filename . "\n";
}
}
-68
View File
@@ -1,68 +0,0 @@
package {package}
{load warning.tpl}
{if !empty($imports)}
import (
{foreach ($imports as $import)}
"{import}"
{/foreach}
)
{/if}
{if !empty($structs)}
type ({foreach $structs as $struct}
{if strpos($name, "Literal") !== false}
{foreach $struct.fields as $field}
{field}{newline}
{/foreach}
{else}
// {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.dbname}{$field.dbname}{else}{$field.name|decamel}{/if}"`{newline}
{/foreach}
changed []string
}
{/if}{/foreach}
)
{/if}
{foreach $structs as $struct}
// New constructs a new instance of {struct.name}
func ({struct.name}) New() *{struct.name} {
return &{struct.name}{}
}
{/foreach}
{foreach $structs as $struct}
{foreach $struct.fields as $field}
// Get the value of {field.name}
func ({self} *{struct.name}) Get{field.name}() {field.type} {
return {self}.{field.name}
}
// Set the value of {field.name}
func ({self} *{struct.name}) Set{field.name}(value {field.type}) *{struct.name} {{if !$field.complex}
if {self}.{field.name} != value {
{self}.changed = append({self}.changed, "{field.name}")
{self}.{field.name} = value
}
{else}
{self}.changed = append({self}.changed, "{field.name}")
{self}.{field.name} = value
{/if}
return {self}
}
{/foreach}
// Changes returns the names of changed fields
func ({self} *{struct.name}) Changes() []string {
return {self}.changed
}
{/foreach}