Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
f1fff87e
提交
f1fff87e
authored
9月 19, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
nacos support username password
上级
dae148c3
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
23 行增加
和
8 行删除
+23
-8
init_app.go
application/init_app.go
+7
-0
xpkg.yaml
conf/xpkg.yaml
+2
-0
init.go
config/init.go
+4
-0
nacos.go
config/nacos.go
+2
-2
nacos.types.go
config/nacos.types.go
+4
-0
nacos.go
rd/nacos/nacos.go
+4
-6
没有找到文件。
application/init_app.go
浏览文件 @
f1fff87e
...
...
@@ -128,7 +128,14 @@ func nacosRegisterInstance() (err error) {
c
.
Rd
.
Nacos
.
ServiceName
=
conf
.
App
.
Name
c
.
Rd
.
Nacos
.
ServiceIP
=
localhost
c
.
Rd
.
Nacos
.
ServicePort
=
conf
.
HTTP
.
Port
if
c
.
Rd
.
Nacos
.
Username
==
""
&&
c
.
ConfCenter
.
Nacos
.
Username
!=
""
{
c
.
Rd
.
Nacos
.
Username
=
c
.
ConfCenter
.
Nacos
.
Username
}
if
c
.
Rd
.
Nacos
.
Password
==
""
&&
c
.
ConfCenter
.
Nacos
.
Password
!=
""
{
c
.
Rd
.
Nacos
.
Password
=
c
.
ConfCenter
.
Nacos
.
Password
}
})
config
.
Read
(
func
(
c
*
config
.
Config
)
{
copier
.
Copy
(
&
conf
,
c
)
})
...
...
conf/xpkg.yaml
浏览文件 @
f1fff87e
...
...
@@ -63,6 +63,8 @@ rd:
enable
:
true
healthy
:
true
ephemeral
:
true
username
:
nacos
password
:
4RSl6H3w!xEs
database
:
-
name
:
"
operator"
...
...
config/init.go
浏览文件 @
f1fff87e
...
...
@@ -109,6 +109,8 @@ func nacosConf() {
namespace
:=
readEnvVarWithDefault
(
"NACOS_NAMESPACE"
,
""
)
dataID
:=
readEnvVarWithDefault
(
"NACOS_DATA_ID"
,
"conf.yaml"
)
group
:=
readEnvVarWithDefault
(
"NACOS_GROUP"
,
"DEFAULT_GROUP"
)
username
:=
readEnvVarWithDefault
(
"NACOS_USERNAME"
,
"nacos"
)
password
:=
readEnvVarWithDefault
(
"NACOS_PASSWORD"
,
"123456"
)
logger
.
Infof
(
"[conf]conf host:%s namespace:%s dataId:%s group:%s"
,
host
,
namespace
,
dataID
,
group
)
Cfg
.
ConfCenter
.
Nacos
.
IPs
=
strings
.
Split
(
host
,
","
)
Cfg
.
ConfCenter
.
Nacos
.
Port
=
cast
.
ToInt
(
port
)
...
...
@@ -116,6 +118,8 @@ func nacosConf() {
Cfg
.
ConfCenter
.
Nacos
.
DataID
=
dataID
Cfg
.
ConfCenter
.
Nacos
.
Group
=
group
Cfg
.
ConfCenter
.
Nacos
.
ContextPath
=
contextPath
Cfg
.
ConfCenter
.
Nacos
.
Username
=
username
Cfg
.
ConfCenter
.
Nacos
.
Password
=
password
logger
.
Debug
(
"[conf]nacos "
,
logger
.
Any
(
"conf"
,
Cfg
.
ConfCenter
.
Nacos
))
}
...
...
config/nacos.go
浏览文件 @
f1fff87e
...
...
@@ -60,8 +60,8 @@ func (x *NacosClient) Connect() *NacosClient {
constant
.
WithUpdateCacheWhenEmpty
(
true
),
//
constant
.
WithLogDir
(
"/tmp/nacos/log"
),
// 日志目录
constant
.
WithCacheDir
(
"/tmp/nacos/cache"
),
// 缓存目录
// constant.WithUsername("nacos"),
// 用户名
// constant.WithPassword("nacos"),
// 密码
constant
.
WithUsername
(
x
.
cfg
.
Username
),
// 用户名
constant
.
WithPassword
(
x
.
cfg
.
Password
),
// 密码
)
logger
.
Debug
(
"[conf][nacos]"
,
logger
.
Any
(
"x.cfg"
,
x
.
cfg
))
serverConfigs
:=
make
([]
constant
.
ServerConfig
,
0
,
len
(
x
.
cfg
.
IPs
))
...
...
config/nacos.types.go
浏览文件 @
f1fff87e
...
...
@@ -7,6 +7,8 @@ type NacosConfConfig struct {
ContextPath
string
`yaml:"context" json:"context"`
// nacos server context path
DataID
string
`yaml:"dataId" json:"dataId"`
// nacos config dataId
Group
string
`yaml:"group" json:"group"`
// nacos config group
Username
string
`yaml:"username" json:"username"`
// nacos username
Password
string
`yaml:"password" json:"password"`
// nacos password
}
type
NacosSvcConfig
struct
{
...
...
@@ -23,4 +25,6 @@ type NacosSvcConfig struct {
Enable
bool
`yaml:"enable" json:"enable"`
// service instance enable
Healthy
bool
`yaml:"healthy" json:"healthy"`
// service instance healthy
Ephemeral
bool
`yaml:"ephemeral" json:"ephemeral"`
// service instance ephemeral
Username
string
`yaml:"username" json:"username"`
//
Password
string
`yaml:"password" json:"password"`
//
}
rd/nacos/nacos.go
浏览文件 @
f1fff87e
...
...
@@ -7,7 +7,6 @@ import (
"github.com/nacos-group/nacos-sdk-go/model"
"github.com/nacos-group/nacos-sdk-go/vo"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
)
type
NacosServiceClient
struct
{
...
...
@@ -24,22 +23,21 @@ func NewWithConfig(cfg *config.NacosSvcConfig) (*NacosServiceClient, error) {
serverConfigs
:=
make
([]
constant
.
ServerConfig
,
0
,
len
(
cfg
.
IPs
))
for
_
,
ip
:=
range
cfg
.
IPs
{
serverConfig
:=
constant
.
NewServerConfig
(
ip
,
//
Nacos服务地址
uint64
(
cfg
.
Port
),
//
Nacos服务端口
ip
,
//
uint64
(
cfg
.
Port
),
//
constant
.
WithContextPath
(
cfg
.
Context
),
)
serverConfigs
=
append
(
serverConfigs
,
*
serverConfig
)
}
nnc
.
sc
=
serverConfigs
logger
.
Debug
(
"[rd][nacos]"
,
logger
.
Any
(
"nnc.cfg"
,
nnc
.
cfg
))
nnc
.
cc
=
constant
.
NewClientConfig
(
constant
.
WithNamespaceId
(
nnc
.
cfg
.
Namespace
),
// 命名空间ID
constant
.
WithTimeoutMs
(
5000
),
// 请求超时时间
constant
.
WithNotLoadCacheAtStart
(
false
),
// 启动时不读取缓存
constant
.
WithLogDir
(
"/tmp/nacos/log"
),
// 日志目录
constant
.
WithCacheDir
(
"/tmp/nacos/cache"
),
// 缓存目录
// constant.WithUsername("nacos"),
// 用户名
// constant.WithPassword("nacos"),
// 密码
constant
.
WithUsername
(
nnc
.
cfg
.
Username
),
// 用户名
constant
.
WithPassword
(
nnc
.
cfg
.
Password
),
// 密码
)
namingClient
,
err
:=
clients
.
NewNamingClient
(
vo
.
NacosClientParam
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论