diff --git a/protoc-gen-grpc-gateway/main.go b/protoc-gen-grpc-gateway/main.go index fca2f83fc7c..30e4c0cf5de 100644 --- a/protoc-gen-grpc-gateway/main.go +++ b/protoc-gen-grpc-gateway/main.go @@ -49,7 +49,7 @@ func main() { defer glog.Flush() if *versionFlag { - fmt.Printf("Version %v, commit %v, built at %v\n", version, commit, date) + fmt.Printf("Version %v, commit %v, built at %v\n", readVersion(), commit, date) os.Exit(0) } diff --git a/protoc-gen-grpc-gateway/main_go1.18.go b/protoc-gen-grpc-gateway/main_go1.18.go new file mode 100644 index 00000000000..65af78587e6 --- /dev/null +++ b/protoc-gen-grpc-gateway/main_go1.18.go @@ -0,0 +1,13 @@ +//go:build go1.18 + +package main + +import "runtime/debug" + +func readVersion() string { + v, ok := debug.ReadBuildInfo() + if !ok { + return version + } + return v.Main.Version +} diff --git a/protoc-gen-grpc-gateway/main_go_less1.18.go b/protoc-gen-grpc-gateway/main_go_less1.18.go new file mode 100644 index 00000000000..0b8f63cc71a --- /dev/null +++ b/protoc-gen-grpc-gateway/main_go_less1.18.go @@ -0,0 +1,7 @@ +//go:build !go1.18 + +package main + +func readVersion() string { + return version +} diff --git a/protoc-gen-openapiv2/main.go b/protoc-gen-openapiv2/main.go index 092d6fa9dbc..1e28ba4df02 100644 --- a/protoc-gen-openapiv2/main.go +++ b/protoc-gen-openapiv2/main.go @@ -56,7 +56,7 @@ func main() { defer glog.Flush() if *versionFlag { - fmt.Printf("Version %v, commit %v, built at %v\n", version, commit, date) + fmt.Printf("Version %v, commit %v, built at %v\n", readVersion(), commit, date) os.Exit(0) } diff --git a/protoc-gen-openapiv2/main_go1.18.go b/protoc-gen-openapiv2/main_go1.18.go new file mode 100644 index 00000000000..65af78587e6 --- /dev/null +++ b/protoc-gen-openapiv2/main_go1.18.go @@ -0,0 +1,13 @@ +//go:build go1.18 + +package main + +import "runtime/debug" + +func readVersion() string { + v, ok := debug.ReadBuildInfo() + if !ok { + return version + } + return v.Main.Version +} diff --git a/protoc-gen-openapiv2/main_go_less1.18.go b/protoc-gen-openapiv2/main_go_less1.18.go new file mode 100644 index 00000000000..0b8f63cc71a --- /dev/null +++ b/protoc-gen-openapiv2/main_go_less1.18.go @@ -0,0 +1,7 @@ +//go:build !go1.18 + +package main + +func readVersion() string { + return version +}