← history for yats.go
c619e6cbyats.go50 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/gocql/gocql"
)

func main() {

	configuration := GetConfig(os.Getenv("HOME") + "/.nojs-db.json")

	conn_string := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
		configuration.DB_USERNAME,
		configuration.DB_PASSWORD,
		configuration.DB_HOST,
		configuration.DB_PORT,
		configuration.DB_NAME)

	fmt.Println(conn_string)

	cluster := gocql.NewCluster(configuration.DB_HOST)
	cluster.Authenticator = gocql.PasswordAuthenticator{Username: configuration.DB_USERNAME, Password: configuration.DB_PASSWORD}
	cluster.Keyspace = configuration.DB_NAME

	session, _ := cluster.CreateSession()

	defer session.Close()

	var peer string
	var peers []string

	//localCql := "SELECT id FROM shp_user"
	localCql := "SELECT peer FROM system.peers"

	iter := session.Query(localCql).Iter()

	for iter.Scan(&peer) {
		peers = append(peers, peer)
	}

	if err := iter.Close(); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("peers = %s\n", peers)

}