diff --git a/main.go b/main.go index 84bcf3b..f2666f2 100644 --- a/main.go +++ b/main.go @@ -26,14 +26,21 @@ func main() { protogen.Options{}.Run(func(gen *protogen.Plugin) error { gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) + // 以代码生成根目录为基准;gen.Files 无 service 时不创建 internal/{server,logic} + serviceCount := 0 + for _, f := range gen.Files { + serviceCount += len(f.Services) + } + if serviceCount == 0 { + return nil + } + if !utils.PathExists("./internal") { os.MkdirAll("./internal", 0755) } - if !utils.PathExists("./internal/server") { os.MkdirAll("./internal/server", 0755) } - if !utils.PathExists("./internal/logic") { os.MkdirAll("./internal/logic", 0755) } @@ -47,13 +54,7 @@ func main() { } } - err := generateNewServerFile(ServicesName) - if err != nil { - return err - - } - - return nil + return generateNewServerFile(ServicesName) }) }