init module
This commit is contained in:
parent
41a804eac9
commit
b15cf7a95b
|
@ -13,3 +13,5 @@
|
|||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
.idea
|
|
@ -0,0 +1,10 @@
|
|||
package zookeeper
|
||||
|
||||
import "strconv"
|
||||
|
||||
// GetFloat64Value ...
|
||||
func GetFloat64Value(path string) float64 {
|
||||
s := GetStringValue(path)
|
||||
v, _ := strconv.ParseFloat(s, 64)
|
||||
return v
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package zookeeper
|
||||
|
||||
import "strconv"
|
||||
|
||||
// GetIntValue ...
|
||||
func GetIntValue(path string) int {
|
||||
s := GetStringValue(path)
|
||||
v, _ := strconv.Atoi(s)
|
||||
return v
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package zookeeper
|
||||
|
||||
import "fmt"
|
||||
|
||||
// GetStringValue ...
|
||||
func GetStringValue(path string) string {
|
||||
value, _, err := zkClient.Get(path)
|
||||
if err != nil {
|
||||
fmt.Printf("Get value from path %s err: %v\n", path, err)
|
||||
}
|
||||
return string(value)
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
module github.com/Selly-Modules/zookeeper
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414 h1:AJNDS0kP60X8wwWFvbLPwDuojxubj9pbfK7pjHw0vKg=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
|
@ -0,0 +1,31 @@
|
|||
package zookeeper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
"github.com/samuel/go-zookeeper/zk"
|
||||
)
|
||||
|
||||
var zkClient *zk.Conn
|
||||
|
||||
// Connect ...
|
||||
func Connect(uri string) error {
|
||||
c, _, err := zk.Connect([]string{uri}, time.Second*30)
|
||||
if err != nil {
|
||||
fmt.Println("Error when connect to Zookeeper", uri, err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(aurora.Green("*** CONNECTED TO ZOOKEEPER: " + uri))
|
||||
|
||||
// Set client
|
||||
zkClient = c
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue