-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (43 loc) · 1.19 KB
/
main.go
File metadata and controls
55 lines (43 loc) · 1.19 KB
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 (
"encoding/json"
"os"
"github.com/layer5io/nighthawk-go/apinighthawk"
// "fortio.org/fortio/fhttp"
"fortio.org/fortio/periodic"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func init() {
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.JSONFormatter{})
// Output to stdout instead of the default stderr
log.SetOutput(os.Stdout)
}
func main() {
// Duration in seconds nighthawk default format
testConfig := &apinighthawk.NighthawkConfig{
Thread: 2,
DurationInSeconds: 5,
QPS: 2,
URL: "https://www.github.com",
}
result, err := apinighthawk.NighthawkRun(testConfig)
if err != nil {
log.Error("Failed to run load test: ", err)
return
}
var result1 periodic.RunnerResults
err = json.Unmarshal(result, &result1)
if err != nil {
log.Error("Error while unmarshaling Nighthawk results to the FortioHTTPRunner: ", err)
return
}
resultsMap := map[string]interface{}{}
err = json.Unmarshal(result, &resultsMap)
if err != nil {
log.Error("Error while unmarshaling Nighthawk results to map: ", err)
return
}
log.Infof("Mapped version of the test: %+#v", resultsMap)
}