| 1234567891011121314151617181920212223242526272829303132 |
- package comp
- import (
- "encoding/json"
- "fmt"
- pb "git.wanbits.io/joe/franklin/protos"
- "git.wanbits.io/joe/kettle/etcd"
- "time"
- )
- var (
- GEtcdc *etcd.EtcdClient
- )
- func ConnectEtcd(c *pb.ConfConf) (*etcd.EtcdClient, error) {
- GEtcdc, err := etcd.New(c.Addrs, c.Username, c.Password, time.Duration(c.Timeout)*time.Second)
- return GEtcdc, err
- }
- func RegisterSelf(path string, c *pb.AppConf, conf *pb.AppConfConf) error {
- sconf, err := json.Marshal(conf)
- if err != nil {
- return err
- }
- fullpath := fmt.Sprintf("%s/%v", path, c.Id)
- leaseId, err := GEtcdc.PutWithLife(fullpath, string(sconf), 2)
- if err != nil {
- return err
- }
- return GEtcdc.KeepAlive(leaseId)
- }
|