diff --git a/README.md b/README.md index 06e5d6d..22be594 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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. @@ -43,4 +43,9 @@ data_models: type: varchar - name: name type: varchar -``` \ No newline at end of file +``` + +## TODO + +- [ ] http routes +- [ ] improve data model to struct. add more types. \ No newline at end of file diff --git a/service.go b/service.go index 3ce7c80..b8ce13f 100644 --- a/service.go +++ b/service.go @@ -91,16 +91,20 @@ func parseProto(cfg Config) (serviceDef, error) { return serviceDef{}, fmt.Errorf("failed to parse compiled proto go file: %w", err) } - importStrs := []string{} - 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, "/")}, "/")) - + imports := parseImports(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 {