diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-21 02:34:43 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-21 02:34:43 +0700 |
| commit | b8e4a6d776707bf857430ddc3666aae794a87edf (patch) | |
| tree | 601ffeaac1b0a34d88f8be903ff81bd62e0fdf03 /http_target.go | |
| parent | 6e27a84dba52e68fe7b75df50190934ab96c1946 (diff) | |
| download | gorankusu-b8e4a6d776707bf857430ddc3666aae794a87edf.tar.xz | |
all: fix all linter warnings
Some linter, govet, warns about possible copied Mutex on HttpRequest.
To fix this we implement method clone and Stringer on HttpRequest.
Diffstat (limited to 'http_target.go')
| -rw-r--r-- | http_target.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/http_target.go b/http_target.go index b209c0d..94a5609 100644 --- a/http_target.go +++ b/http_target.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "sort" + "strings" "sync" libhttp "github.com/shuLhan/share/lib/http" @@ -53,7 +54,7 @@ type HttpTarget struct { RequestType libhttp.RequestType Method libhttp.RequestMethod - AttackLocker sync.Mutex `json:"-"` // Use this inside the Attack to lock resource. + sync.Mutex `json:"-"` // Use this inside the Attack to lock resource. // AllowAttack if its true the "Attack" button will be showed on user // interface and client will be allowed to run load testing on this @@ -65,6 +66,26 @@ type HttpTarget struct { IsCustomizable bool } +// clone the source HttpTarget. +// This method is provided to prevent the sync.Mutex being copied. +func (ht *HttpTarget) clone(src *HttpTarget) { + ht.Params = src.Params + ht.ConvertParams = src.ConvertParams + ht.Headers = src.Headers + ht.Run = src.Run + ht.PreAttack = src.PreAttack + ht.Attack = src.Attack + ht.ID = src.ID + ht.Name = src.Name + ht.Hint = src.Hint + ht.Path = src.Path + ht.Results = src.Results + ht.RequestType = src.RequestType + ht.Method = src.Method + ht.AllowAttack = src.AllowAttack + ht.IsCustomizable = src.IsCustomizable +} + func (ht *HttpTarget) init() (err error) { if len(ht.Name) == 0 { return fmt.Errorf("HttpTarget.Name is empty") @@ -132,3 +153,16 @@ func (ht *HttpTarget) sortResults() { return ht.Results[x].Name > ht.Results[y].Name }) } + +func (ht *HttpTarget) String() string { + var sb strings.Builder + + fmt.Fprintf(&sb, `ID:%s Name:%s Hint:%s Path:%s `+ + `Params:%v ConvertParams:%v Headers:%v `+ + `AllowAttack:%t IsCustomizable:%t`, + ht.ID, ht.Name, ht.Hint, ht.Path, + ht.Params, ht.ConvertParams, ht.Headers, + ht.AllowAttack, ht.IsCustomizable) + + return sb.String() +} |
