Skip to content

Commit aa96dec

Browse files
committed
Add the package version
To make it easier to understand which particular version of the package is being used at a moment, and to eg. use the package version in logging and metrics, add a version string as an exported constant to the package.
1 parent 49aaca8 commit aa96dec

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ func main() {
179179
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
180180
log.Fatalf("Error parsing the response body: %s", err)
181181
}
182-
// Print version number.
183-
log.Printf("~~~~~~~> Elasticsearch %s", r["version"].(map[string]interface{})["number"])
182+
// Print client and server version numbers.
183+
log.Printf("Client: %s", elasticsearch.Version)
184+
log.Printf("Server: %s", r["version"].(map[string]interface{})["number"])
185+
log.Println(strings.Repeat("~", 37))
184186

185187
// 2. Index documents concurrently
186188
//
@@ -270,11 +272,13 @@ func main() {
270272
log.Println(strings.Repeat("=", 37))
271273
}
272274

273-
// ~~~~~~~> Elasticsearch 7.0.0-SNAPSHOT
274-
// [200 OK] updated; version=1
275-
// [200 OK] updated; version=1
275+
// Client: 7.0.0-SNAPSHOT
276+
// Server: 7.0.0-SNAPSHOT
277+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278+
// [201 Created] updated; version=1
279+
// [201 Created] updated; version=1
276280
// -------------------------------------
277-
// [200 OK] 2 hits; took: 7ms
281+
// [200 OK] 2 hits; took: 5ms
278282
// * ID=1, map[title:Test One]
279283
// * ID=2, map[title:Test Two]
280284
// =====================================

_examples/main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ func main() {
5050
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
5151
log.Fatalf("Error parsing the response body: %s", err)
5252
}
53-
// Print version number.
54-
log.Printf("~~~~~~~> Elasticsearch %s", r["version"].(map[string]interface{})["number"])
53+
// Print client and server version numbers.
54+
log.Printf("Client: %s", elasticsearch.Version)
55+
log.Printf("Server: %s", r["version"].(map[string]interface{})["number"])
56+
log.Println(strings.Repeat("~", 37))
5557

5658
// 2. Index documents concurrently
5759
//

elasticsearch_internal_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ func TestAddrsToURLs(t *testing.T) {
191191
})
192192
}
193193
}
194+
195+
func TestVersion(t *testing.T) {
196+
if Version == "" {
197+
t.Error("Version is empty")
198+
}
199+
}

version.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package elasticsearch
2+
3+
// Version returns the package version as a string.
4+
//
5+
const Version = "7.0.0-SNAPSHOT"

0 commit comments

Comments
 (0)