basic data and api boilerplate
This commit is contained in:
38
data/core.go
Normal file
38
data/core.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
server "go.etcd.io/etcd/server/v3/embed"
|
||||
)
|
||||
|
||||
var Client *clientv3.Client //client for the syncer
|
||||
var dlog *log.Entry
|
||||
|
||||
// Start and embedded ETCD server
|
||||
func StartETCDServer(dir, username, password string) (*server.Etcd, error) {
|
||||
log.Infoln("Starting embedded etcd server")
|
||||
cfg := server.NewConfig()
|
||||
cfg.Dir = dir
|
||||
return server.StartEtcd(cfg)
|
||||
}
|
||||
|
||||
// Init the Data repo for syncer
|
||||
func InitData(url, username, password string) error {
|
||||
dlog = log.WithField("component", "data")
|
||||
dlog.Infoln("Init Data Repo (", url, ")")
|
||||
cli, err := clientv3.New(clientv3.Config{
|
||||
Endpoints: []string{url},
|
||||
DialTimeout: 5 * time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
dlog.Errorln(err)
|
||||
return err
|
||||
}
|
||||
Client = cli
|
||||
initPlayout()
|
||||
dlog.Infoln("Data Repo init completed")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user