This commit is contained in:
cubixle
2021-06-18 21:50:28 +01:00
parent 93a51d9365
commit ea33f7060b
2 changed files with 19 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
# Tuugen # Tuugen
Tuugen takes a tuugen.yml and a grpc proto definition to generate common boiler plate logic. Some of the common boiler plate it generates is http routes, grpc service, data model structs and a main file with some default plumbing. Tuugen takes a tuugen.yml and a grpc proto definition to generate common boiler plate logic. Some of the common boiler plate it generates is http routes, grpc service, basic data model structs and a main file with some default plumbing.
Tuugen adds an interactor package which the http and grpc transport layers use for business logic. Tuugen adds an interactor package which the http and grpc transport layers use for business logic.
@@ -43,4 +43,9 @@ data_models:
type: varchar type: varchar
- name: name - name: name
type: varchar type: varchar
``` ```
## TODO
- [ ] http routes
- [ ] improve data model to struct. add more types.

View File

@@ -91,16 +91,20 @@ func parseProto(cfg Config) (serviceDef, error) {
return serviceDef{}, fmt.Errorf("failed to parse compiled proto go file: %w", err) return serviceDef{}, fmt.Errorf("failed to parse compiled proto go file: %w", err)
} }
importStrs := []string{} imports := parseImports(cfg, f)
servicePath := filepath.Dir(cfg.GRPCFile)
for _, i := range f.Imports {
importStrs = append(importStrs, strings.Replace(i.Path.Value, `"`, "", -1))
}
importStrs = append(importStrs, strings.Join([]string{cfg.ImportPath, strings.TrimLeft(servicePath, "/")}, "/"))
funcs := parseFuncs(cfg, f) funcs := parseFuncs(cfg, f)
return serviceDef{Funcs: funcs, Imports: importStrs}, nil return serviceDef{Funcs: funcs, Imports: imports}, nil
}
func parseImports(cfg Config, f *ast.File) []string {
imports := []string{}
servicePath := filepath.Dir(cfg.GRPCFile)
for _, i := range f.Imports {
imports = append(imports, strings.Replace(i.Path.Value, `"`, "", -1))
}
imports = append(imports, strings.Join([]string{cfg.ImportPath, strings.TrimLeft(servicePath, "/")}, "/"))
return imports
} }
func parseFuncs(cfg Config, f *ast.File) []serviceFuncDef { func parseFuncs(cfg Config, f *ast.File) []serviceFuncDef {