forked from shaonianyr/boomer_locust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget.go
55 lines (40 loc) · 999 Bytes
/
target.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 (
"log"
"net/http"
"time"
"flag"
"github.com/myzhan/boomer"
)
var targetUrl string
func getIndex() {
start := time.Now()
resp, err := http.Get(string(targetUrl))
if err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
elapsed := time.Since(start)
if resp.Status == "200 OK" {
boomer.RecordSuccess("Get", "/", elapsed.Nanoseconds()/int64(time.Millisecond), resp.ContentLength)
} else if resp.Status == "201 Created" {
boomer.RecordSuccess("Get", "/", elapsed.Nanoseconds()/int64(time.Millisecond), resp.ContentLength)
} else {
boomer.RecordFailure("Get", "/", elapsed.Nanoseconds()/int64(time.Millisecond), resp.Status)
}
}
func main() {
flag.StringVar(&targetUrl, "url", "", "url or app:port")
flag.Parse()
if targetUrl == "" {
log.Println("Boomer target url is null")
return
}
log.Println("Boomer target url is", string(targetUrl))
task := &boomer.Task{
Name: "getIndex",
Fn: getIndex,
}
boomer.Run(task)
}