From 85b4b61a32a47676b9d6cf1a87af1c4ba1612529 Mon Sep 17 00:00:00 2001 From: Havoc412 <2993167370@qq.com> Date: Tue, 19 Nov 2024 22:09:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(bootstrap):=20=E6=B7=BB=E5=8A=A0=20Elastic?= =?UTF-8?q?search=20=E5=90=AF=E5=8A=A8=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 config.yml 中添加 ElasticSearch.Start 配置项,用于控制是否启动 Elasticsearch 客户端 - 修改 init() 函数,根据配置项决定是否初始化 Elasticsearch 客户端 - 更新 prompts.yml,保留原有提示内容 --- bootstrap/init.go | 14 ++++++++------ config/config.yml | 1 + config/prompts.yml | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bootstrap/init.go b/bootstrap/init.go index 64fb3f3..0078f33 100644 --- a/bootstrap/init.go +++ b/bootstrap/init.go @@ -125,12 +125,14 @@ func init() { ) // 12. ES 客户端启动 - var err error - variable.ElasticClient, err = elasticsearch.NewClient(elasticsearch.Config{ - Addresses: []string{variable.ConfigYml.GetString("ElasticSearch.Addr")}, - }) - if err != nil { - log.Fatal(my_errors.ErrorsInitConnFail + err.Error()) + if variable.ConfigYml.GetInt("ElasticSearch.Start") == 1 { + var err error + variable.ElasticClient, err = elasticsearch.NewClient(elasticsearch.Config{ + Addresses: []string{variable.ConfigYml.GetString("ElasticSearch.Addr")}, + }) + if err != nil { + log.Fatal(my_errors.ErrorsInitConnFail + err.Error()) + } } } diff --git a/config/config.yml b/config/config.yml index 6657a18..2455305 100644 --- a/config/config.yml +++ b/config/config.yml @@ -173,6 +173,7 @@ QiNiu: SecretKey: "UP5-GmSmAYNbMlSb6LYLuKZ-fT35nlEzGvOKKm9S" ElasticSearch: + Start: 0 # 0 不启动;1 启动 Addr: "http://localhost:9200" UserName: "elastic" Password: "" diff --git a/config/prompts.yml b/config/prompts.yml index 05ce48f..c87e5d4 100644 --- a/config/prompts.yml +++ b/config/prompts.yml @@ -18,4 +18,4 @@ Prompt: ··· {context} ··· - 如果给定的知识库无法让你做出回答,请回答知识库中未找到符合的资料,我不知道。" \ No newline at end of file + 如果给定的知识库无法让你做出回答,请回答知识库中未找到符合的资料,我不知道。" \ No newline at end of file