From 72880bafe5a00badfb213da5c11ec7cb70cdb75f Mon Sep 17 00:00:00 2001 From: gfanton Date: Thu, 12 Jan 2017 14:46:43 +0100 Subject: [PATCH 1/2] Add all arguments --- encoder.go | 18 +++++++++++++++++- main.go | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/encoder.go b/encoder.go index c0ce638..2e37120 100644 --- a/encoder.go +++ b/encoder.go @@ -37,7 +37,7 @@ type Ast struct { Environment []string `json:"environment"` } -func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) { +func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) { e = &GenericTemplateBasedEncoder{ service: service, file: file, @@ -53,6 +53,22 @@ func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.Serv return } +func NewGenericTemplateBasedEncoder(templateDir string, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) { + e = &GenericTemplateBasedEncoder{ + service: nil, + file: file, + templateDir: templateDir, + debug: debug, + destinationDir: destinationDir, + } + + if debug { + log.Printf("new encoder: file=%q template-dir=%q", file.GetName(), templateDir) + } + + return +} + func (e *GenericTemplateBasedEncoder) templates() ([]string, error) { filenames := []string{} diff --git a/main.go b/main.go index 6a4b8e3..0415dca 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/golang/protobuf/protoc-gen-go/generator" ) @@ -32,6 +33,7 @@ func main() { templateDir := "./templates" destinationDir := "." debug := false + all := false if parameter := g.Request.GetParameter(); parameter != "" { for _, param := range strings.Split(parameter, ",") { parts := strings.Split(param, "=") @@ -55,6 +57,15 @@ func main() { log.Printf("Err: invalid value for debug: %q", parts[1]) } break + case "all": + switch strings.ToLower(parts[1]) { + case "true", "t": + all = true + case "false", "f": + default: + log.Printf("Err: invalid value for debug: %q", parts[1]) + } + break default: log.Printf("Err: unknown parameter: %q", param) } @@ -63,8 +74,14 @@ func main() { // Generate the encoders for _, file := range g.Request.GetProtoFile() { + if all { + encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir) + g.Response.File = append(g.Response.File, encoder.Files()...) + continue + } + for _, service := range file.GetService() { - encoder := NewGenericTemplateBasedEncoder(templateDir, service, file, debug, destinationDir) + encoder := NewGenericServiceTemplateBasedEncoder(templateDir, service, file, debug, destinationDir) g.Response.File = append(g.Response.File, encoder.Files()...) } } From 0d32837e5dd22cc0840eeb95f340373171914275 Mon Sep 17 00:00:00 2001 From: gfanton Date: Thu, 12 Jan 2017 15:14:36 +0100 Subject: [PATCH 2/2] Remove useless dependencies --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 0415dca..9f1a6e6 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/golang/protobuf/protoc-gen-go/generator" )