-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (53 loc) · 1.15 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/kardianos/service"
)
const currentVersion = "0.1.0"
var logger service.Logger
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
config := flag.String("config", "", "Full path of configuration file.")
debug := flag.Bool("debug", false, "Debug mode.")
flags := flag.String("service", "", "Control the system service.")
version := flag.Bool("version", false, "Show version.")
flag.Parse()
if *version {
fmt.Println("Version: " + currentVersion)
return
}
svcConfig := &service.Config{
Name: "spac",
DisplayName: "Simple Port Application Checker",
Description: "Enables https calls to checks applications by active / open ports",
}
c := &Service{
Config: *config,
Debug: *debug,
}
s, err := service.New(c, svcConfig)
if err != nil {
log.Fatal(err)
}
if *flags != "" {
err = service.Control(s, *flags)
if err != nil {
log.Printf("Valid actions: %q\n", service.ControlAction)
log.Fatal(err)
}
return
}
logger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
if err = s.Run(); err != nil {
logger.Error(err)
}
}