-
Notifications
You must be signed in to change notification settings - Fork 32
/
whoisd.go
46 lines (42 loc) · 899 Bytes
/
whoisd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"fmt"
"os"
"runtime"
"time"
"github.com/takama/whoisd/config"
"github.com/takama/whoisd/service"
)
// Init "Usage" helper
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Usage = func() {
fmt.Println(config.Usage())
}
}
func main() {
daemonName, daemonDescription := "whoisd", "Whois Daemon"
daemon, err := service.New(daemonName, daemonDescription)
if err != nil {
fmt.Println("Error: ", err)
os.Exit(1)
}
flag.Parse()
if daemon.Config.ShowVersion {
buildTime, err := time.Parse(time.RFC3339, service.Date)
if err != nil {
buildTime = time.Now()
}
fmt.Println(daemonName, service.Version, buildTime.Format(time.RFC3339))
os.Exit(0)
}
status, err := daemon.Run()
if err != nil {
fmt.Println(status, "\nError: ", err)
os.Exit(1)
}
// Wait for logger output
time.Sleep(100 * time.Millisecond)
fmt.Println(status)
}