improve: 使用标准项目结构
This commit is contained in:
9
internal/pkg/dns/util/config.go
Normal file
9
internal/pkg/dns/util/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package dnsUtil
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func DecodeConfig(conf map[string]interface{}, output interface{}) error {
|
||||
return mapstructure.Decode(conf, output)
|
||||
}
|
||||
18
internal/pkg/dns/util/domain.go
Normal file
18
internal/pkg/dns/util/domain.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package dnsUtil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DecodeDomain(domain string) (subStr string, rootDomain string, e error) {
|
||||
t := strings.Split(domain, ".")
|
||||
if len(t) == 1 {
|
||||
return "", "", errors.New("域名不合法")
|
||||
} else if len(t) == 2 {
|
||||
return "@", domain, nil
|
||||
}
|
||||
|
||||
l := len(t)
|
||||
return strings.Join(t[:l-2], "."), strings.Join(t[l-2:l], "."), nil
|
||||
}
|
||||
Reference in New Issue
Block a user