You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2022/10/02 01:27:18 UTC
[pulsar-client-go] branch master updated: read module version info from golang runtime (#856)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new dedbdc4 read module version info from golang runtime (#856)
dedbdc4 is described below
commit dedbdc45c63b06e6a12356785418cd906d6bab3c
Author: Paul Gier <pa...@datastax.com>
AuthorDate: Sat Oct 1 20:27:13 2022 -0500
read module version info from golang runtime (#856)
* read module version info from golang runtime
Instead of maintaining a hard coded version string in the sources, we can get the
version of the pulsar-client-go module used to build the client application.
Signed-off-by: Paul Gier <pa...@datastax.com>
* add test for module version
Signed-off-by: Paul Gier <pa...@datastax.com>
Signed-off-by: Paul Gier <pa...@datastax.com>
---
go.mod | 1 +
go.sum | 6 ++---
pulsar/internal/connection.go | 4 ----
pulsar/internal/version.go | 50 +++++++++++++++++++++++++++++++++++++++++
pulsar/internal/version_test.go | 28 +++++++++++++++++++++++
5 files changed, 82 insertions(+), 7 deletions(-)
diff --git a/go.mod b/go.mod
index 262870c..3c2945a 100644
--- a/go.mod
+++ b/go.mod
@@ -25,5 +25,6 @@ require (
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.8.0
go.uber.org/atomic v1.7.0
+ golang.org/x/mod v0.5.1
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602
)
diff --git a/go.sum b/go.sum
index 906a7ae..faa0746 100644
--- a/go.sum
+++ b/go.sum
@@ -344,7 +344,6 @@ github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
-github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@@ -353,7 +352,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
@@ -421,7 +419,10 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
+golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -749,7 +750,6 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/pulsar/internal/connection.go b/pulsar/internal/connection.go
index 6a410a2..6ca462e 100644
--- a/pulsar/internal/connection.go
+++ b/pulsar/internal/connection.go
@@ -39,10 +39,6 @@ import (
)
const (
- // PulsarVersion FIXME: Before each release, please modify the current Version value.
- PulsarVersion = "0.9.0"
- ClientVersionString = "Pulsar Go " + PulsarVersion
-
PulsarProtocolVersion = int32(pb.ProtocolVersion_v18)
)
diff --git a/pulsar/internal/version.go b/pulsar/internal/version.go
new file mode 100644
index 0000000..089f0dd
--- /dev/null
+++ b/pulsar/internal/version.go
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package internal
+
+import (
+ "runtime/debug"
+
+ "golang.org/x/mod/semver"
+)
+
+const (
+ pulsarClientGoModulePath = "github.com/apache/pulsar-client-go"
+)
+
+var (
+ Version string
+ ClientVersionString string
+)
+
+// init Initializes the module version information by reading
+// the built in golang build info. If the application was not built
+// using go modules then the version string will not be available.
+func init() {
+ if buildInfo, ok := debug.ReadBuildInfo(); ok {
+ for _, dep := range buildInfo.Deps {
+ if dep.Path == pulsarClientGoModulePath {
+ Version = semver.Canonical(dep.Version)
+ ClientVersionString = "Pulsar Go " + Version
+ return
+ }
+ }
+ }
+ Version = "unknown"
+ ClientVersionString = "Pulsar Go version unknown"
+}
diff --git a/pulsar/internal/version_test.go b/pulsar/internal/version_test.go
new file mode 100644
index 0000000..283dc6e
--- /dev/null
+++ b/pulsar/internal/version_test.go
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package internal
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestInitVersion(t *testing.T) {
+ assert.NotEmpty(t, Version, "version string should not be empty")
+}