Skip to content

Commit 2d71140

Browse files
committed
管理平台界面设置中增加“使用的DNS解析库”选项
1 parent e911039 commit 2d71140

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

internal/configloaders/admin_ui_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func loadAdminUIConfig() (*systemconfigs.AdminUIConfig, error) {
9393
}
9494

9595
var config = &systemconfigs.AdminUIConfig{}
96+
config.DNSResolver.Type = nodeconfigs.DNSResolverTypeDefault // 默认值
9697
err = json.Unmarshal(resp.ValueJSON, config)
9798
if err != nil {
9899
logs.Println("[UI_MANAGER]" + err.Error())
@@ -108,7 +109,7 @@ func loadAdminUIConfig() (*systemconfigs.AdminUIConfig, error) {
108109
}
109110

110111
func defaultAdminUIConfig() *systemconfigs.AdminUIConfig {
111-
return &systemconfigs.AdminUIConfig{
112+
var config = &systemconfigs.AdminUIConfig{
112113
ProductName: langs.DefaultMessage(codes.AdminUI_DefaultProductName),
113114
AdminSystemName: langs.DefaultMessage(codes.AdminUI_DefaultSystemName),
114115
ShowOpenSourceInfo: true,
@@ -117,6 +118,8 @@ func defaultAdminUIConfig() *systemconfigs.AdminUIConfig {
117118
DefaultPageSize: 10,
118119
TimeZone: nodeconfigs.DefaultTimeZoneLocation,
119120
}
121+
config.DNSResolver.Type = nodeconfigs.DNSResolverTypeDefault
122+
return config
120123
}
121124

122125
// 修改时区

internal/nodes/admin_node.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
99
"github.com/TeaOSLab/EdgeAdmin/internal/events"
1010
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
11+
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
1112
"github.com/iwind/TeaGo"
1213
"github.com/iwind/TeaGo/Tea"
1314
"github.com/iwind/TeaGo/lists"
@@ -87,6 +88,9 @@ func (this *AdminNode) Run() {
8788
// 启动API节点
8889
this.startAPINode()
8990

91+
// 设置DNS相关
92+
this.setupDNS()
93+
9094
// 启动IP库
9195
this.startIPLibrary()
9296

@@ -254,6 +258,33 @@ func (this *AdminNode) addPortsToFirewall() {
254258
utils.AddPortsToFirewall(ports)
255259
}
256260

261+
// 设置DNS相关
262+
func (this *AdminNode) setupDNS() {
263+
config, loadErr := configloaders.LoadAdminUIConfig()
264+
if loadErr != nil {
265+
// 默认使用go原生
266+
err := os.Setenv("GODEBUG", "netdns=go")
267+
if err != nil {
268+
logs.Println("[DNS_RESOLVER]set env failed: " + err.Error())
269+
}
270+
return
271+
}
272+
273+
var err error
274+
switch config.DNSResolver.Type {
275+
case nodeconfigs.DNSResolverTypeGoNative:
276+
err = os.Setenv("GODEBUG", "netdns=go")
277+
case nodeconfigs.DNSResolverTypeCGO:
278+
err = os.Setenv("GODEBUG", "netdns=cgo")
279+
default:
280+
// 默认使用go原生
281+
err = os.Setenv("GODEBUG", "netdns=go")
282+
}
283+
if err != nil {
284+
logs.Println("[DNS_RESOLVER]set env failed: " + err.Error())
285+
}
286+
}
287+
257288
// 启动API节点
258289
func (this *AdminNode) startAPINode() {
259290
var configPath = Tea.Root + "/edge-api/configs/api.yaml"

internal/web/actions/default/settings/ui/index.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (this *IndexAction) RunPost(params struct {
5555
LogoFile *actions.File
5656
DefaultPageSize int
5757
TimeZone string
58+
DnsResolverType string
5859

5960
SupportModuleCDN bool
6061
SupportModuleNS bool
@@ -85,6 +86,7 @@ func (this *IndexAction) RunPost(params struct {
8586
config.ShowVersion = params.ShowVersion
8687
config.Version = params.Version
8788
config.TimeZone = params.TimeZone
89+
config.DNSResolver.Type = params.DnsResolverType
8890

8991
if params.DefaultPageSize > 0 {
9092
config.DefaultPageSize = params.DefaultPageSize
@@ -111,10 +113,10 @@ func (this *IndexAction) RunPost(params struct {
111113
this.ErrorPage(err)
112114
return
113115
}
114-
fileId := createResp.FileId
116+
var fileId = createResp.FileId
115117

116118
// 上传内容
117-
buf := make([]byte, 512*1024)
119+
var buf = make([]byte, 512*1024)
118120
reader, err := params.FaviconFile.OriginFile.Open()
119121
if err != nil {
120122
this.ErrorPage(err)
@@ -158,10 +160,10 @@ func (this *IndexAction) RunPost(params struct {
158160
this.ErrorPage(err)
159161
return
160162
}
161-
fileId := createResp.FileId
163+
var fileId = createResp.FileId
162164

163165
// 上传内容
164-
buf := make([]byte, 512*1024)
166+
var buf = make([]byte, 512*1024)
165167
reader, err := params.LogoFile.OriginFile.Open()
166168
if err != nil {
167169
this.ErrorPage(err)

web/views/@default/settings/ui/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ <h4>其他</h4>
109109
</select>
110110
</div>
111111
</div>
112-
<p class="comment">显示时间使用的时区。</p>
112+
<p class="comment">当前管理系统显示时间使用的时区。</p>
113+
</td>
114+
</tr>
115+
<tr>
116+
<td>使用的DNS解析库</td>
117+
<td>
118+
<select class="ui dropdown auto-width" name="dnsResolverType" v-model="config.dnsResolver.type">
119+
<option value="default">默认</option>
120+
<option value="cgo">CGO</option>
121+
<option value="goNative">Go原生</option>
122+
</select>
123+
<p class="comment">当前管理系统使用的DNS解析库;修改此项配置后,需要重启管理系统进程才会生效;通常不需要修改;如要修改,请在专家指导下进行。</p>
113124
</td>
114125
</tr>
115126
</table>

0 commit comments

Comments
 (0)