Files
EdgeAPI/internal/db/models/node_cluster_model_ext.go

24 lines
560 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package models
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
)
// DecodeDNSConfig 解析DNS配置
func (this *NodeCluster) DecodeDNSConfig() (*dnsconfigs.ClusterDNSConfig, error) {
if len(this.Dns) == 0 {
// 一定要返回一个默认的值防止产生nil
return &dnsconfigs.ClusterDNSConfig{
NodesAutoSync: false,
ServersAutoSync: false,
}, nil
}
dnsConfig := &dnsconfigs.ClusterDNSConfig{}
err := json.Unmarshal([]byte(this.Dns), &dnsConfig)
if err != nil {
return nil, err
}
return dnsConfig, nil
}