Reapply "题目记录.md"

This reverts commit ef954349d4.
This commit is contained in:
2025-08-15 03:57:05 +08:00
parent ef954349d4
commit 2cf33460f8
2 changed files with 167 additions and 0 deletions

33
goroutine/task.go Normal file
View File

@@ -0,0 +1,33 @@
package goroutine
import (
"context"
"fmt"
clientv3 "go.etcd.io/etcd/client/v3"
"goLearn/model"
"time"
)
func Runtask(ctx context.Context) {
ctx2 := ctx.Value("value").(model.Task)
fmt.Println(ctx2.Id)
config := clientv3.Config{
Endpoints: []string{"127.0.0.1:2379"}, // etcd节点地址集群模式可填多个
DialTimeout: 5 * time.Second, // 连接超时时间
// 如需认证,添加以下配置
// Username: "root",
// Password: "123456",
}
// 2. 建立连接
client, err := clientv3.New(config)
if err != nil {
fmt.Printf("连接etcd失败: %v\n", err)
return
}
defer client.Close() // 程序退出时关闭连接
fmt.Println("成功连接到etcd")
}