basic data and api boilerplate

This commit is contained in:
2023-12-19 08:31:55 +01:00
parent 16ce61ae38
commit c894e3438f
12 changed files with 1016 additions and 6 deletions

38
data/core.go Normal file
View 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
}