added godoc examples
parent
37a0b22df3
commit
5eb3e5fc1a
|
@ -102,7 +102,7 @@ func writePoints(con *client.Client) {
|
|||
bps := client.BatchPoints{
|
||||
Points: pts,
|
||||
Database: MyDB,
|
||||
RetentionPolicy: "default", // ie for evar!
|
||||
RetentionPolicy: "default", // ie forevar!
|
||||
}
|
||||
_, err := con.Write(bps)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
package client_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/influxdb/client"
|
||||
)
|
||||
|
||||
func ExampleNewClient() {
|
||||
host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
conf := client.Config{
|
||||
URL: *host,
|
||||
Username: "root",
|
||||
Password: "root",
|
||||
}
|
||||
con, err := client.NewClient(conf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Connection", con)
|
||||
}
|
||||
|
||||
func ExampleClient_Ping() {
|
||||
host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
con, err := client.NewClient(
|
||||
client.Config{
|
||||
URL: *host,
|
||||
Username: "root",
|
||||
Password: "root",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dur, ver, err := con.Ping()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Happy as a hippo! %v, %s", dur, ver)
|
||||
}
|
||||
|
||||
func ExampleClient_Query() {
|
||||
host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
con, err := client.NewClient(client.Config{
|
||||
URL: *host,
|
||||
Username: "root",
|
||||
Password: "root",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
q := client.Query{
|
||||
Command: "select count(value) from shapes",
|
||||
Database: "square_holes",
|
||||
}
|
||||
if results, err := con.Query(q); err == nil && results.Error() == nil {
|
||||
log.Println(results.Results)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_Write() {
|
||||
host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
con, err := client.NewClient(client.Config{
|
||||
URL: *host,
|
||||
Username: "root",
|
||||
Password: "root",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var (
|
||||
shapes = []string{"circle", "rectangle", "square", "triangle"}
|
||||
colors = []string{"red", "blue", "green"}
|
||||
sampleSize = 1000
|
||||
pts = make([]client.Point, sampleSize)
|
||||
)
|
||||
|
||||
rand.Seed(42)
|
||||
for i := 0; i < sampleSize; i++ {
|
||||
pts[i] = client.Point{
|
||||
Name: "shapes",
|
||||
Tags: map[string]string{
|
||||
"color": strconv.Itoa(rand.Intn(len(colors))),
|
||||
"shape": strconv.Itoa(rand.Intn(len(shapes))),
|
||||
},
|
||||
Fields: map[string]interface{}{
|
||||
"value": rand.Intn(sampleSize),
|
||||
},
|
||||
Timestamp: time.Now(),
|
||||
Precision: "s",
|
||||
}
|
||||
}
|
||||
|
||||
bps := client.BatchPoints{
|
||||
Points: pts,
|
||||
Database: "BumbeBeeTuna",
|
||||
RetentionPolicy: "default", // ie forevar!
|
||||
}
|
||||
_, err = con.Write(bps)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue