Skip to content

Commit dd057e6

Browse files
committed
supported command line arguments
1 parent 35eacad commit dd057e6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"io/ioutil"
67
"log"
78
"regexp"
89
"strconv"
910
"strings"
10-
"flag"
1111

1212
. "nickns/resolver"
1313

@@ -23,15 +23,13 @@ type configOptions struct {
2323
}
2424

2525
var (
26-
portOpt = flag.Int("p", 5300, "Listening udp port")
27-
ttlOpt = flag.Int("t", 3600, "Interval for keeping DNS cache")
2826
confPathOpt = flag.String("c", "config.toml", "Path to config.toml")
2927
hostPathOpt = flag.String("n", "hosts.toml", "Path to hosts.toml")
3028
)
3129

3230
var confOptions = configOptions{
33-
Port: *portOpt,
34-
TTL: *ttlOpt,
31+
Port: 5300,
32+
TTL: 3600,
3533
Domains: []string{"local.", "example.com."},
3634
}
3735

@@ -95,10 +93,13 @@ func main() {
9593
if err != nil {
9694
log.Fatalln(err)
9795
}
98-
if _, err := toml.Decode(string(content), &confPathOpt); err != nil {
96+
if _, err := toml.Decode(string(content), &confOptions); err != nil {
9997
log.Fatalln(err)
10098
}
10199

100+
// set path hosts.toml
101+
SetEsxiConfigPath("hosts.toml")
102+
102103
// attach request handler func
103104
for _, domain := range confOptions.Domains {
104105
dns.HandleFunc(domain, dnsRequestHandler)

resolver/esxi/esxi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ type esxiNode struct {
2828
}
2929
type esxiNodes map[string]esxiNode
3030

31+
var EsxiNodeConfPath string = "hosts.toml"
32+
3133
// Get SSH Nodes from hosts.toml
3234
func loadAllEsxiNodes() esxiNodes {
33-
content, err := ioutil.ReadFile("hosts.toml")
35+
content, err := ioutil.ReadFile(EsxiNodeConfPath)
3436
if err != nil {
3537
log.Fatalln(err)
3638
}

resolver/resolver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ type QueryCache struct {
2121
type QueryCaches []QueryCache
2222
*/
2323

24+
// Config for esxi hosts info
25+
func SetEsxiConfigPath(hostFilePath string) {
26+
EsxiNodeConfPath = hostFilePath
27+
}
28+
2429
// Resolve type 'A' record
2530
func ResolveRecordTypeA(hostname string) string {
2631
/* cache hit

0 commit comments

Comments
 (0)