-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (47 loc) · 1.09 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
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"github.com/hashicorp/logutils"
shabik "github.com/sadeemio/shabik/libshabik"
)
var debug, version bool
func SetLogging(level string, f io.Writer) *logutils.LevelFilter {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"},
MinLevel: logutils.LogLevel(level),
Writer: f,
}
log.SetOutput(filter)
return filter
}
func init() {
flag.BoolVar(&debug, "d", false, "run in debug mode")
flag.BoolVar(&version, "v", false, "print version and exit (shorthand)")
flag.Parse()
}
func main() {
// Set logging output, append to file and create if not exist
f, err := os.OpenFile(shabik.LOGFILE, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Error opening logfile: %v", err)
}
defer f.Close()
if debug {
SetLogging("DEBUG", f)
} else {
SetLogging("INFO", f)
}
if version {
fmt.Printf("Shabik Version: %v \n", shabik.VERSION)
os.Exit(0)
}
// Connect to node.sadeem.io
go shabik.FetchData()
// Serve DHCP
dhcp := shabik.NewDHCPHandler()
dhcp.RunServer()
}