1 Star 0 Fork 0

wheatj/sdns

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
Ciro S. Costa 提交于 2017-08-20 10:18 . Adds version
package main
import (
"fmt"
"os"
"github.com/alexflint/go-arg"
"github.com/pkg/errors"
. "github.com/cirocosta/sdns/lib"
util "github.com/cirocosta/sdns/util"
)
var version = "master"
// config contains the structure for retrieval of
// the SDNS configuration from the command line.
type config struct {
Port int `arg:"-p,env,help:port to listen to"`
Address string `arg:"-a,env,help:address to bind to"`
Debug bool `arg:"-d,env,help:turn debug mode on"`
Recursors []string `arg:"-r,--recursor,help:list of recursors to honor"`
Domains []string `arg:"positional,help:list of domains"`
}
func (c *config) Version() string {
return fmt.Sprintf("\nsdns - %s\n", version)
}
var (
args = &config{
Port: 1053,
Debug: true,
Recursors: []string{
"8.8.8.8:53",
"8.8.4.4:53",
},
}
sdnsConfig = SdnsConfig{}
s Sdns
err error
)
func main() {
arg.MustParse(args)
if len(args.Domains) > 0 {
sdnsConfig.Domains = make([]*Domain, len(args.Domains))
for idx, domainString := range args.Domains {
domain := &Domain{}
mapping, err := util.CsvStringToMap(domainString)
if err != nil {
fmt.Fprintf(os.Stderr,
"ERROR: Malformed domain configuration - %s",
errors.Cause(err))
os.Exit(1)
}
name, present := mapping["domain"]
if !present {
fmt.Fprintf(os.Stderr,
"ERROR: Malformed domain configuration. "+
"A domain name must be present")
os.Exit(1)
}
if present {
domain.Name = name[0]
}
ips, present := mapping["ip"]
if present {
domain.Addresses = ips
}
nameservers, present := mapping["ns"]
if present {
domain.Nameservers = nameservers
}
sdnsConfig.Domains[idx] = domain
}
}
sdnsConfig.Recursors = args.Recursors
sdnsConfig.Debug = args.Debug
sdnsConfig.Address = args.Address
sdnsConfig.Port = args.Port
s, err = NewSdns(sdnsConfig)
if err != nil {
fmt.Fprintf(os.Stderr,
"ERROR: Couldn't instantiate sdns - %s",
errors.Cause(err))
os.Exit(1)
}
err = s.Listen()
if err != nil {
fmt.Fprintf(os.Stderr,
"ERROR: Errored listening - %s",
errors.Cause(err))
os.Exit(1)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wheatj/sdns.git
[email protected]:wheatj/sdns.git
wheatj
sdns
sdns
master

搜索帮助