aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-03-27 16:31:23 +0700
committerShulhan <ms@kilabit.info>2021-03-27 16:31:23 +0700
commitd36d1eee17e2b38109a76b735191003d14d35336 (patch)
tree4849943a09ceb19c3bd7fa168f7a979a15d74065
parent19eb62d2f744ea7a08e2e6393e82a67788c3e8ff (diff)
downloadgorankusu-d36d1eee17e2b38109a76b735191003d14d35336.tar.xz
all: make the HttpTarget Name to be required
Previously, the HttpTarget Name field is optional, and the ID is derived from Path. This changes make the Name field become required and changes the ID to be derived from Name instead of Path, because one or more same path can be used by more HttpTarget.
-rw-r--r--http_target.go24
-rw-r--r--target.go6
2 files changed, 19 insertions, 11 deletions
diff --git a/http_target.go b/http_target.go
index 129bc8e..e8ddfb6 100644
--- a/http_target.go
+++ b/http_target.go
@@ -5,6 +5,7 @@
package trunks
import (
+ "fmt"
"os"
"path/filepath"
"sync"
@@ -31,13 +32,13 @@ type HttpAttackHandler func(rr *RunRequest) vegeta.Targeter
type HttpPreAttackHandler func(rr *RunRequest)
type HttpTarget struct {
+ // Name of target, required.
+ Name string
+
// ID of target, optional.
- // If its empty, it will generated using value from Path.
+ // If its empty, it will generated using value from Name.
ID string
- // Name of target, optional, default to Path.
- Name string
-
Method libhttp.RequestMethod
Path string
RequestType libhttp.RequestType
@@ -58,12 +59,13 @@ type HttpTarget struct {
AllowAttack bool
}
-func (ht *HttpTarget) init() {
- if len(ht.ID) == 0 {
- ht.ID = generateID(ht.Path)
- }
+func (ht *HttpTarget) init() (err error) {
if len(ht.Name) == 0 {
- ht.Name = ht.Path
+ return fmt.Errorf("HttpTarget.Name is empty")
+
+ }
+ if len(ht.ID) == 0 {
+ ht.ID = generateID(ht.Name)
}
if ht.Headers == nil {
ht.Headers = KeyValue{}
@@ -71,6 +73,10 @@ func (ht *HttpTarget) init() {
if ht.Params == nil {
ht.Params = KeyValue{}
}
+ if len(ht.Path) == 0 {
+ ht.Path = "/"
+ }
+ return nil
}
func (ht *HttpTarget) deleteResult(result *AttackResult) {
diff --git a/target.go b/target.go
index 6bdf4f4..7a1f414 100644
--- a/target.go
+++ b/target.go
@@ -52,9 +52,11 @@ func (target *Target) init() (err error) {
}
for _, ht := range target.HttpTargets {
- ht.init()
+ err = ht.init()
+ if err != nil {
+ return fmt.Errorf("Target.init %s: %w", target.Name, err)
+ }
}
-
for _, wst := range target.WebSocketTargets {
err = wst.init()
if err != nil {