1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-12 02:28:05 +02:00
kratos/tool/protobuf/pkg/naming/go_naming.go
Tony e5fe1e4f63 Kratos protobuf protoc (#71)
* add cross-platform protoc
* add protobuf generator
2019-05-05 20:33:09 +08:00

28 lines
706 B
Go

package naming
import (
"path"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
)
// GoFileName returns the output name for the generated Go file.
func GoFileName(f *descriptor.FileDescriptorProto, suffix string) string {
name := *f.Name
if ext := path.Ext(name); ext == ".pb" || ext == ".proto" || ext == ".protodevel" {
name = name[:len(name)-len(ext)]
}
name += suffix
// Does the file have a "go_package" option? If it does, it may override the
// filename.
if impPath, _, ok := goPackageOption(f); ok && impPath != "" {
// Replace the existing dirname with the declared import path.
_, name = path.Split(name)
name = path.Join(impPath, name)
return name
}
return name
}