diff --git a/cmd/protoc-gen-go-drpc/main.go b/cmd/protoc-gen-go-drpc/main.go index 9cda156..0bb3f3b 100644 --- a/cmd/protoc-gen-go-drpc/main.go +++ b/cmd/protoc-gen-go-drpc/main.go @@ -15,8 +15,9 @@ import ( ) type config struct { - protolib string - json bool + protolib string + json bool + standalone bool } func main() { @@ -24,6 +25,7 @@ func main() { var conf config flags.StringVar(&conf.protolib, "protolib", "google.golang.org/protobuf", "which protobuf library to use for encoding") flags.BoolVar(&conf.json, "json", true, "generate encoders with json support") + flags.BoolVar(&conf.standalone, "standalone", false, "generate code that work outside of generated messages") protogen.Options{ ParamFunc: flags.Set, @@ -40,7 +42,11 @@ func main() { } func generateFile(plugin *protogen.Plugin, file *protogen.File, conf config) { - gf := plugin.NewGeneratedFile(file.GeneratedFilenamePrefix+"_drpc.pb.go", file.GoImportPath) + path := file.GoImportPath + if conf.standalone { + path = "." + } + gf := plugin.NewGeneratedFile(file.GeneratedFilenamePrefix+"_drpc.pb.go", path) d := &drpc{gf, file} d.P("// Code generated by protoc-gen-go-drpc. DO NOT EDIT.")