【优化】优化 cfg go的生成代码

main
walon 2021-11-27 13:36:38 +08:00
parent 7ff3467d35
commit b0d64bb967
10 changed files with 15 additions and 24 deletions

View File

@ -10,30 +10,25 @@ namespace Luban.Job.Cfg.Generate
{ {
public override string Render(DefBean b) public override string Render(DefBean b)
{ {
string package = DefAssembly.LocalAssebmly.TopModule;
var template = StringTemplateUtil.GetTemplate("config/go_bin/bean"); var template = StringTemplateUtil.GetTemplate("config/go_bin/bean");
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package }); var result = template.RenderCode(b);
return result; return result;
} }
public override string Render(DefTable p) public override string Render(DefTable p)
{ {
string package = DefAssembly.LocalAssebmly.TopModule;
var template = StringTemplateUtil.GetTemplate("config/go_bin/table"); var template = StringTemplateUtil.GetTemplate("config/go_bin/table");
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package }); var result = template.RenderCode(p);
return result; return result;
} }
public override string RenderService(string name, string module, List<DefTable> tables) public override string RenderService(string name, string module, List<DefTable> tables)
{ {
string package = DefAssembly.LocalAssebmly.TopModule;
var template = StringTemplateUtil.GetTemplate("config/go_bin/tables"); var template = StringTemplateUtil.GetTemplate("config/go_bin/tables");
var result = template.Render(new { var result = template.Render(new {
Name = name, Name = name,
Namespace = module, Namespace = module,
Tables = tables, Tables = tables,
Package = package,
}); });
return result; return result;
} }

View File

@ -10,34 +10,27 @@ namespace Luban.Job.Cfg.Generate
{ {
public override string Render(DefBean b) public override string Render(DefBean b)
{ {
string package = "cfg";
var template = StringTemplateUtil.GetTemplate("config/go_json/bean"); var template = StringTemplateUtil.GetTemplate("config/go_json/bean");
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package }); var result = template.RenderCode(b);
return result; return result;
} }
public override string Render(DefTable p) public override string Render(DefTable p)
{ {
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
string package = "cfg";
var template = StringTemplateUtil.GetTemplate("config/go_json/table"); var template = StringTemplateUtil.GetTemplate("config/go_json/table");
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package }); var result = template.RenderCode(p);
return result; return result;
} }
public override string RenderService(string name, string module, List<DefTable> tables) public override string RenderService(string name, string module, List<DefTable> tables)
{ {
string package = "cfg";
var template = StringTemplateUtil.GetTemplate("config/go_json/tables"); var template = StringTemplateUtil.GetTemplate("config/go_json/tables");
var result = template.Render(new { var result = template.Render(new {
Name = name, Name = name,
Namespace = module, Namespace = module,
Tables = tables, Tables = tables,
Package = package,
}); });
return result; return result;

View File

@ -16,7 +16,10 @@ namespace Luban.Job.Proto.Generate
protected override string Render(DefEnum e) protected override string Render(DefEnum e)
{ {
return RenderUtil.RenderCsEnumClass(e); var template = StringTemplateUtil.GetTemplate($"common/{RenderTemplateDir}/enum");
var result = template.Render(e);
return result;
} }
protected override string Render(DefBean b) protected override string Render(DefBean b)

View File

@ -1,4 +1,4 @@
package {{package}} package {{x.top_module}}
const ( const (
{{~for item in x.items ~}} {{~for item in x.items ~}}

View File

@ -6,7 +6,7 @@
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
-}} -}}
package {{package}} package {{x.top_module}}
import ( import (
"bright/serialization" "bright/serialization"

View File

@ -9,7 +9,7 @@
index_field2 = x.index_field2 index_field2 = x.index_field2
-}} -}}
package {{package}} package {{x.top_module}}
import "bright/serialization" import "bright/serialization"

View File

@ -1,5 +1,5 @@
package {{package}} package {{namespace}}
import "bright/serialization" import "bright/serialization"

View File

@ -6,7 +6,7 @@
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
-}} -}}
package {{package}} package {{x.top_module}}
{{x.go_json_import}} {{x.go_json_import}}

View File

@ -9,7 +9,7 @@
index_field2 = x.index_field2 index_field2 = x.index_field2
-}} -}}
package {{package}} package {{x.top_module}}
{{~if x.is_map_table~}} {{~if x.is_map_table~}}
type {{go_full_name}} struct { type {{go_full_name}} struct {

View File

@ -1,5 +1,5 @@
package {{package}} package {{namespace}}
type JsonLoader func(string) ([]map[string]interface{}, error) type JsonLoader func(string) ([]map[string]interface{}, error)