Skip to content

Commit

Permalink
Use go_package option if found.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Du committed Jun 19, 2017
1 parent d64f531 commit 42ec8ec
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions protoc-gen-grpc-gateway/gengateway/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGenerato
}
name := file.GetName()
ext := filepath.Ext(name)
base := strings.TrimSuffix(name, ext)
output := fmt.Sprintf("%s.pb.gw.go", base)
// Check if a `go_package` option was specified and use it as the base output path
goPkg := file.GetOptions().GetGoPackage()
var base string
var output string
if goPkg == "" {
base = strings.TrimSuffix(name, ext)
output = fmt.Sprintf("%s.pb.gw.go", base)
} else {
base = strings.TrimSuffix(filepath.Base(name), ext)
output = fmt.Sprintf("%s.pb.gw.go", goPkg)
}
files = append(files, &plugin.CodeGeneratorResponse_File{
Name: proto.String(output),
Content: proto.String(string(formatted)),
Expand Down

0 comments on commit 42ec8ec

Please sign in to comment.