@@ -11,7 +11,7 @@ import (
1111)
1212
1313const (
14- VERSION string = "0.5.1 "
14+ VERSION string = "0.5.2 "
1515 DefaultUserAgent string = "Dodo/" + VERSION
1616 ProxyCheckURL string = "https://www.google.com"
1717 DefaultMethod string = "GET"
@@ -21,10 +21,6 @@ const (
2121 MaxDodosCountForProxies uint = 20 // Max dodos count for proxy check
2222)
2323
24- type IConfig interface {
25- MergeConfigs (newConfig IConfig ) IConfig
26- }
27-
2824type RequestConfig struct {
2925 Method string
3026 URL * url.URL
@@ -37,6 +33,7 @@ type RequestConfig struct {
3733 Proxies []Proxy
3834 Body []string
3935 Yes bool
36+ NoProxyCheck bool
4037}
4138
4239func (config * RequestConfig ) Print () {
@@ -47,6 +44,12 @@ func (config *RequestConfig) Print() {
4744 {Number : 2 , WidthMax : 50 },
4845 })
4946
47+ newHeaders := make (map [string ][]string )
48+ newHeaders ["User-Agent" ] = []string {DefaultUserAgent }
49+ for k , v := range config .Headers {
50+ newHeaders [k ] = v
51+ }
52+
5053 t .AppendHeader (table.Row {"Request Configuration" })
5154 t .AppendRow (table.Row {"Method" , config .Method })
5255 t .AppendSeparator ()
@@ -56,16 +59,18 @@ func (config *RequestConfig) Print() {
5659 t .AppendSeparator ()
5760 t .AppendRow (table.Row {"Dodos" , config .DodosCount })
5861 t .AppendSeparator ()
59- t .AppendRow (table.Row {"Request " , config .RequestCount })
62+ t .AppendRow (table.Row {"Requests " , config .RequestCount })
6063 t .AppendSeparator ()
6164 t .AppendRow (table.Row {"Params" , utils .MarshalJSON (config .Params , 3 )})
6265 t .AppendSeparator ()
63- t .AppendRow (table.Row {"Headers" , utils .MarshalJSON (config . Headers , 3 )})
66+ t .AppendRow (table.Row {"Headers" , utils .MarshalJSON (newHeaders , 3 )})
6467 t .AppendSeparator ()
6568 t .AppendRow (table.Row {"Cookies" , utils .MarshalJSON (config .Cookies , 3 )})
6669 t .AppendSeparator ()
6770 t .AppendRow (table.Row {"Proxies Count" , len (config .Proxies )})
6871 t .AppendSeparator ()
72+ t .AppendRow (table.Row {"Proxy Check" , ! config .NoProxyCheck })
73+ t .AppendSeparator ()
6974 t .AppendRow (table.Row {"Body" , utils .MarshalJSON (config .Body , 3 )})
7075
7176 t .Render ()
@@ -87,11 +92,32 @@ func (config *RequestConfig) GetMaxConns(minConns uint) uint {
8792}
8893
8994type Config struct {
90- Method string `json:"method" validate:"http_method"` // custom validations: http_method
91- URL string `json:"url" validate:"http_url,required"`
92- Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
93- DodosCount uint `json:"dodos_count" validate:"gte=1"`
94- RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
95+ Method string `json:"method" validate:"http_method"` // custom validations: http_method
96+ URL string `json:"url" validate:"http_url,required"`
97+ Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
98+ DodosCount uint `json:"dodos_count" validate:"gte=1"`
99+ RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
100+ NoProxyCheck utils.Option [bool ] `json:"no_proxy_check"`
101+ }
102+
103+ func NewConfig (
104+ method string ,
105+ timeout uint32 ,
106+ dodosCount uint ,
107+ requestCount uint ,
108+ noProxyCheck utils.Option [bool ],
109+ ) * Config {
110+ if noProxyCheck == nil {
111+ noProxyCheck = utils .NewNoneOption [bool ]()
112+ }
113+
114+ return & Config {
115+ Method : method ,
116+ Timeout : timeout ,
117+ DodosCount : dodosCount ,
118+ RequestCount : requestCount ,
119+ NoProxyCheck : noProxyCheck ,
120+ }
95121}
96122
97123func (config * Config ) MergeConfigs (newConfig * Config ) {
@@ -110,6 +136,9 @@ func (config *Config) MergeConfigs(newConfig *Config) {
110136 if newConfig .RequestCount != 0 {
111137 config .RequestCount = newConfig .RequestCount
112138 }
139+ if ! newConfig .NoProxyCheck .IsNone () {
140+ config .NoProxyCheck = newConfig .NoProxyCheck
141+ }
113142}
114143
115144func (config * Config ) SetDefaults () {
@@ -125,6 +154,9 @@ func (config *Config) SetDefaults() {
125154 if config .RequestCount == 0 {
126155 config .RequestCount = DefaultRequestCount
127156 }
157+ if config .NoProxyCheck .IsNone () {
158+ config .NoProxyCheck = utils .NewOption (false )
159+ }
128160}
129161
130162type Proxy struct {
@@ -134,16 +166,29 @@ type Proxy struct {
134166}
135167
136168type JSONConfig struct {
137- Config
169+ * Config
138170 Params map [string ][]string `json:"params"`
139171 Headers map [string ][]string `json:"headers"`
140172 Cookies map [string ][]string `json:"cookies"`
141173 Proxies []Proxy `json:"proxies" validate:"dive"`
142174 Body []string `json:"body"`
143175}
144176
177+ func NewJSONConfig (
178+ config * Config ,
179+ params map [string ][]string ,
180+ headers map [string ][]string ,
181+ cookies map [string ][]string ,
182+ proxies []Proxy ,
183+ body []string ,
184+ ) * JSONConfig {
185+ return & JSONConfig {
186+ config , params , headers , cookies , proxies , body ,
187+ }
188+ }
189+
145190func (config * JSONConfig ) MergeConfigs (newConfig * JSONConfig ) {
146- config .Config .MergeConfigs (& newConfig .Config )
191+ config .Config .MergeConfigs (newConfig .Config )
147192 if len (newConfig .Params ) != 0 {
148193 config .Params = newConfig .Params
149194 }
@@ -162,13 +207,23 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
162207}
163208
164209type CLIConfig struct {
165- Config
210+ * Config
166211 Yes bool `json:"yes" validate:"omitempty"`
167212 ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
168213}
169214
215+ func NewCLIConfig (
216+ config * Config ,
217+ yes bool ,
218+ configFile string ,
219+ ) * CLIConfig {
220+ return & CLIConfig {
221+ config , yes , configFile ,
222+ }
223+ }
224+
170225func (config * CLIConfig ) MergeConfigs (newConfig * CLIConfig ) {
171- config .Config .MergeConfigs (& newConfig .Config )
226+ config .Config .MergeConfigs (newConfig .Config )
172227 if newConfig .ConfigFile != "" {
173228 config .ConfigFile = newConfig .ConfigFile
174229 }
0 commit comments