package main import ( "context" "flag" "log" "novit.tech/direktil/etcdb" "novit.tech/direktil/etcdb/leader" ) var ( Normal = etcdb.ClientSpec{ URLs: "http://127.0.0.1:2379", Prefix: "etcdbl/", } Secure = etcdb.ClientSpec{ URLs: "http://127.0.0.1:2379", Prefix: "etcdbs/", } data = etcdb.Encrypted(Secure.Sub("encset/")) myInt = etcdb.SingletonSpec[int]{Spec: data, Key: "my-int"} myStrings = etcdb.SetSpec[string]{Spec: data.Sub("my-strings")} data2 = etcdb.Encrypted(Secure.Sub("encset/")) myStrings2 = etcdb.SetSpec[string]{Spec: data2.Sub("my-strings")} myLeader = leader.Spec{ Etcd: &Normal, Election: "my-leader", OnLeader: onLeader, } ) func main() { flag.Parse() Normal.MustConnect() Secure.MustConnect() myLeader.RunProcess() } func onLeader(ctx context.Context) { if err := data.Unlock(ctx, []byte("uifee6ooB")); err != nil { log.Print("failed to unlock: ", err) } data.AddKey(ctx, []byte("xish1yaiG")) if err := data2.Unlock(ctx, []byte("xish1yaiG")); err != nil { log.Print("failed to unlock 2nd set: ", err) } v := "value" if true { d1 := myStrings.In(ctx) err := d1.Put("key", v) log.Printf("d1[key] => err=%v %q", err, v) } if true { d2 := myStrings2.In(ctx) v, ok, err := d2.Get("key") log.Printf("d2[key] => ok=%v err=%v value=%q", ok, err, v) } <-ctx.Done() log.Print("leader context done") }