File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "flag"
4
5
"fmt"
5
6
"io/ioutil"
6
7
"log"
7
8
"regexp"
8
9
"strconv"
9
10
"strings"
10
- "flag"
11
11
12
12
. "nickns/resolver"
13
13
@@ -23,15 +23,13 @@ type configOptions struct {
23
23
}
24
24
25
25
var (
26
- portOpt = flag .Int ("p" , 5300 , "Listening udp port" )
27
- ttlOpt = flag .Int ("t" , 3600 , "Interval for keeping DNS cache" )
28
26
confPathOpt = flag .String ("c" , "config.toml" , "Path to config.toml" )
29
27
hostPathOpt = flag .String ("n" , "hosts.toml" , "Path to hosts.toml" )
30
28
)
31
29
32
30
var confOptions = configOptions {
33
- Port : * portOpt ,
34
- TTL : * ttlOpt ,
31
+ Port : 5300 ,
32
+ TTL : 3600 ,
35
33
Domains : []string {"local." , "example.com." },
36
34
}
37
35
@@ -95,10 +93,13 @@ func main() {
95
93
if err != nil {
96
94
log .Fatalln (err )
97
95
}
98
- if _ , err := toml .Decode (string (content ), & confPathOpt ); err != nil {
96
+ if _ , err := toml .Decode (string (content ), & confOptions ); err != nil {
99
97
log .Fatalln (err )
100
98
}
101
99
100
+ // set path hosts.toml
101
+ SetEsxiConfigPath ("hosts.toml" )
102
+
102
103
// attach request handler func
103
104
for _ , domain := range confOptions .Domains {
104
105
dns .HandleFunc (domain , dnsRequestHandler )
Original file line number Diff line number Diff line change @@ -28,9 +28,11 @@ type esxiNode struct {
28
28
}
29
29
type esxiNodes map [string ]esxiNode
30
30
31
+ var EsxiNodeConfPath string = "hosts.toml"
32
+
31
33
// Get SSH Nodes from hosts.toml
32
34
func loadAllEsxiNodes () esxiNodes {
33
- content , err := ioutil .ReadFile ("hosts.toml" )
35
+ content , err := ioutil .ReadFile (EsxiNodeConfPath )
34
36
if err != nil {
35
37
log .Fatalln (err )
36
38
}
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ type QueryCache struct {
21
21
type QueryCaches []QueryCache
22
22
*/
23
23
24
+ // Config for esxi hosts info
25
+ func SetEsxiConfigPath (hostFilePath string ) {
26
+ EsxiNodeConfPath = hostFilePath
27
+ }
28
+
24
29
// Resolve type 'A' record
25
30
func ResolveRecordTypeA (hostname string ) string {
26
31
/* cache hit
You can’t perform that action at this time.
0 commit comments