-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·51 lines (40 loc) · 1011 Bytes
/
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
package main
import (
"database/sql"
"flag"
"log"
"net/http"
_ "github.com/go-sql-driver/mysql"
)
var (
webBindAddr string
allowFrom IPNetList
telegramChatID string
telegramToken string
ixcDSN string
ixcDB *sql.DB
)
func main() {
var err error
flag.StringVar(&webBindAddr, "web-bind", ":8080", "web bind address")
flag.StringVar(&ixcDSN, "ixc-dsn", "", "IXC database")
flag.StringVar(&telegramToken, "telegram-token", "", "Telegram token")
flag.StringVar(&telegramChatID, "telegram-chat-id", "", "Telegram chat ID")
allowFromStr := flag.String("allow-from", "", "limit permitted IPs")
flag.Parse()
err = allowFrom.ParseArg(*allowFromStr)
if err != nil {
log.Fatal(err)
}
ixcDB, err = sql.Open("mysql", ixcDSN)
if err != nil {
log.Fatal(err)
}
ixcDB.SetMaxOpenConns(5)
err = ixcDB.Ping()
if err != nil {
log.Fatal(err)
}
http.HandleFunc("/ping", pingHandler)
log.Fatal(http.ListenAndServe(webBindAddr, allowNetworkWrapper(http.DefaultServeMux)))
}