-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
219 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ LICENSE | |
*.yml | ||
build/ | ||
.github/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/BurntSushi/toml" | ||
"github.com/jamesits/libiferr/exception" | ||
"github.com/jamesits/snd" | ||
"github.com/jamesits/snd/pkg/config" | ||
"github.com/jamesits/snd/pkg/dns_server" | ||
"log" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
var conf *config.Config | ||
var configFilePath *string | ||
var showVersionOnly *bool | ||
var mainThreadWaitGroup = &sync.WaitGroup{} | ||
|
||
func main() { | ||
// parse flags | ||
var err error | ||
configFilePath = flag.String("Config", "/etc/snd/Config.toml", "Config directory") | ||
showVersionOnly = flag.Bool("version", false, "show version and quit") | ||
flag.Parse() | ||
|
||
if *showVersionOnly { | ||
fmt.Println(snd.GetVersionFullString()) | ||
return | ||
} else { | ||
log.Println(snd.GetVersionFullString()) | ||
} | ||
|
||
// parse Config file | ||
conf = &config.Config{} | ||
metaData, err := toml.DecodeFile(*configFilePath, conf) | ||
exception.HardFailWithReason("failed to read the config file", err) | ||
|
||
// print unknown configs | ||
for _, key := range metaData.Undecoded() { | ||
log.Printf("Unknown key %q in the Config file, maybe a typo?", key.String()) | ||
} | ||
|
||
// fix Config and fill in defaults | ||
conf.FixConfig() | ||
|
||
// listen on all the configured listeners | ||
for _, elem := range conf.Listen { | ||
r := strings.SplitN(*elem, ":", 2) | ||
go func() { | ||
mainThreadWaitGroup.Add(1) | ||
defer mainThreadWaitGroup.Done() | ||
go dns_server.ListenSync(conf, r[0], r[1]) | ||
}() | ||
} | ||
|
||
mainThreadWaitGroup.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package config | ||
|
||
import "strings" | ||
|
||
func ensureDotAtRight(s *string) *string { | ||
if !strings.HasSuffix(*s, ".") { | ||
ret := *s + "." | ||
return &ret | ||
} else { | ||
return s | ||
} | ||
} | ||
|
||
func ensureNoDotAtLeft(s *string) *string { | ||
if !strings.HasPrefix(*s, ".") { | ||
ret := strings.TrimLeft(*s, ".") | ||
return &ret | ||
} else { | ||
return s | ||
} | ||
} |
Oops, something went wrong.