-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (43 loc) · 1.04 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
package main
import (
"flag"
"fmt"
"github.com/vvampirius/parcel-tracker/config"
"log"
"net/http"
"os"
)
const VERSION = `0.7`
var (
ErrorLog = log.New(os.Stderr, `error#`, log.Lshortfile)
DebugLog = log.New(os.Stdout, `debug#`, log.Lshortfile)
)
func helpText() {
fmt.Println(`# https://github.com/vvampirius/parcel-tracker`)
flag.PrintDefaults()
}
func main() {
help := flag.Bool("h", false, "print this help")
ver := flag.Bool("v", false, "Show version")
configFilePath := flag.String("c", "config.yaml", "configuration file")
flag.Parse()
if *help {
helpText()
os.Exit(0)
}
if *ver {
fmt.Println(VERSION)
os.Exit(0)
}
fmt.Printf("Starting version %s...\n", VERSION)
configFile, err := config.NewConfigFile(*configFilePath)
if err != nil { os.Exit(1) }
core, err := NewCore(configFile)
if err != nil { os.Exit(1) }
go core.ScanRoutine()
http.HandleFunc("/", core.TelegramHttpHandler)
err = http.ListenAndServe(configFile.Config.Listen, nil) // set listen port
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}