-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
56 lines (44 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
55
56
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.App{}
app.Name = "URLTesterBot"
app.Version = fmt.Sprintf("%s (%s)", Version, Commit)
app.Usage = "Service that schedules URL monitoring by user request. \nAll the configuration is done by the final user itself by using the telegram bot."
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "telegram-token",
Usage: "Telegram API token for the bot to work.",
EnvVar: "TELEGRAM_TOKEN",
},
cli.StringFlag{
Name: "db-path",
Usage: "Database path where to store user requests and statuses.",
EnvVar: "DB_PATH",
Value: "./urltester.db",
},
cli.Int64SliceFlag{
Name: "admins",
Usage: "Telegram UserIDs that can administer bot accesses.",
EnvVar: "ADMINS",
},
}
app.Action = startAPI
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func startAPI(c *cli.Context) error {
tester := urlTester{
token: c.GlobalString("telegram-token"),
dbpath: c.GlobalString("db-path"),
admins: c.GlobalInt64Slice("admins"),
}
return tester.botstart()
}