package main import ( "context" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/client/v3/concurrency" "time" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"106.54.33.152:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { panic(err) } defer cli.Close() grant, _ := cli.Grant(context.Background(), 15) session, err := concurrency.NewSession(cli, concurrency.WithLease(grant.ID)) if err != nil { panic(err) } m := concurrency.NewLocker(session, "lock/test") m.Lock() defer m.Unlock() time.Sleep(20 * time.Second) }