-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1.06 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 (
"flag"
"fmt"
"log"
"os"
"time"
)
const VERSION = `0.1.1`
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/http-slave`)
flag.PrintDefaults()
}
func main() {
help := flag.Bool("h", false, "print this help")
ver := flag.Bool("v", false, "show version")
contactUrl := flag.String("u", os.Getenv(`URL`), "contact url")
contactInterval := flag.Int("i", 60, "contact interval (second)")
flag.Parse()
if *help {
helpText()
os.Exit(0)
}
if *ver {
fmt.Println(VERSION)
os.Exit(0)
}
fmt.Printf("Starting version %s...\n", VERSION)
for {
if task, err := GetTask(*contactUrl); err == nil {
go func() {
data, exitCode, spent, err := ExecTask(task)
if err != nil {
data = []byte(err.Error())
exitCode = 255
}
RespondTask(task.RespondUrl, data, exitCode, spent)
}()
if task.ImmediatelyNext { continue }
}
time.Sleep(time.Second * time.Duration(*contactInterval))
}
}