aboutsummaryrefslogtreecommitdiff
path: root/example/example.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-03-24 00:39:55 +0700
committerShulhan <ms@kilabit.info>2021-03-24 00:39:55 +0700
commit896e55e6406b0837041c0aad75035f5839083e25 (patch)
tree81a059e9f22e4fe3a54d1296bd08806071b7bca6 /example/example.go
parent5ffaf533cd7e4d26365b342f0f6d15bd8d1ff5d1 (diff)
downloadgorankusu-896e55e6406b0837041c0aad75035f5839083e25.tar.xz
all: move BaseUrl from AttackOptions to Target
The BaseUrl seems like not a good fit on AttackOptions since its should never changes, so we move it to the Target.
Diffstat (limited to 'example/example.go')
-rw-r--r--example/example.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/example/example.go b/example/example.go
index 9a91ebb..b2ef46c 100644
--- a/example/example.go
+++ b/example/example.go
@@ -92,9 +92,9 @@ func (ex *Example) registerEndpoints() (err error) {
func (ex *Example) registerTargets() (err error) {
targetHttp := &trunks.Target{
- Name: "Example",
+ Name: "Example HTTP",
+ BaseUrl: fmt.Sprintf("http://%s", ex.trunks.Env.ListenAddress),
Opts: &trunks.AttackOptions{
- BaseUrl: fmt.Sprintf("http://%s", ex.trunks.Env.ListenAddress),
Duration: 300 * time.Second,
RatePerSecond: 1,
},
@@ -160,7 +160,7 @@ func (ex *Example) pathExamplePostForm(epr *libhttp.EndpointRequest) ([]byte, er
func (ex *Example) runExampleGet(req *trunks.RunRequest) ([]byte, error) {
if req.Target.HttpClient == nil {
- req.Target.HttpClient = libhttp.NewClient(req.Target.Opts.BaseUrl, nil, true)
+ req.Target.HttpClient = libhttp.NewClient(req.Target.BaseUrl, nil, true)
}
_, resbody, err := req.Target.HttpClient.Get(
req.HttpTarget.Path,
@@ -175,7 +175,7 @@ func (ex *Example) runExampleGet(req *trunks.RunRequest) ([]byte, error) {
func (ex *Example) preattackExampleGet(rr *trunks.RunRequest) {
ex.targetExampleGet = vegeta.Target{
Method: rr.HttpTarget.Method.String(),
- URL: fmt.Sprintf("%s%s", rr.Target.Opts.BaseUrl, rr.HttpTarget.Path),
+ URL: fmt.Sprintf("%s%s", rr.Target.BaseUrl, rr.HttpTarget.Path),
Header: rr.HttpTarget.Headers.ToHttpHeader(),
}
@@ -198,7 +198,7 @@ func (ex *Example) attackExampleGet(rr *trunks.RunRequest) vegeta.Targeter {
func (ex *Example) runExamplePostForm(req *trunks.RunRequest) ([]byte, error) {
if req.Target.HttpClient == nil {
- req.Target.HttpClient = libhttp.NewClient(req.Target.Opts.BaseUrl, nil, true)
+ req.Target.HttpClient = libhttp.NewClient(req.Target.BaseUrl, nil, true)
}
_, resbody, err := req.Target.HttpClient.PostForm(
req.HttpTarget.Path,
@@ -213,7 +213,7 @@ func (ex *Example) runExamplePostForm(req *trunks.RunRequest) ([]byte, error) {
func (ex *Example) preattackExamplePostForm(rr *trunks.RunRequest) {
ex.targetExamplePostForm = vegeta.Target{
Method: rr.HttpTarget.Method.String(),
- URL: fmt.Sprintf("%s%s", rr.Target.Opts.BaseUrl, rr.HttpTarget.Path),
+ URL: fmt.Sprintf("%s%s", rr.Target.BaseUrl, rr.HttpTarget.Path),
Header: rr.HttpTarget.Headers.ToHttpHeader(),
}