Skip to content

Instantly share code, notes, and snippets.

@olivere
Created July 28, 2015 08:50
Show Gist options
  • Save olivere/64023cb33dba39d7b5d3 to your computer and use it in GitHub Desktop.
Save olivere/64023cb33dba39d7b5d3 to your computer and use it in GitHub Desktop.
elastic-issue-107-2.go
package main
import (
"fmt"
"log"
"sync"
elastic "gopkg.in/olivere/elastic.v2"
)
var (
clientInit sync.Once
client *elastic.Client
)
func Client() *elastic.Client {
clientInit.Do(func() {
c, err := elastic.NewClient()
if err != nil {
panic(err)
}
client = c
})
return client
}
func main() {
var i int64
for {
_, _, err := Client().Ping().URL("http://127.0.0.1:9200").Do()
if err != nil {
log.Fatal(err)
}
i++
fmt.Printf("%8d\r", i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment