| Conditions | 4 |
| Total Lines | 54 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package cmd |
||
| 138 | func startScan(logger *logrus.Logger, cnf *scan.Config, u *url.URL) error { |
||
| 139 | c, err := client.NewClientFromConfig( |
||
| 140 | cnf.TimeoutInMilliseconds, |
||
| 141 | cnf.Socks5Url, |
||
| 142 | cnf.UserAgent, |
||
| 143 | cnf.UseCookieJar, |
||
| 144 | cnf.Cookies, |
||
| 145 | cnf.Headers, |
||
| 146 | u, |
||
| 147 | ) |
||
| 148 | if err != nil { |
||
| 149 | return errors.Wrap(err, "failed to build client") |
||
| 150 | } |
||
| 151 | |||
| 152 | dict, err := dictionary.NewDictionaryFrom(cnf.DictionaryPath, c) |
||
| 153 | if err != nil { |
||
| 154 | return errors.Wrap(err, "failed to build dictionary") |
||
| 155 | } |
||
| 156 | |||
| 157 | targetProducer := producer.NewDictionaryProducer(cnf.HTTPMethods, dict, cnf.ScanDepth) |
||
| 158 | reproducer := producer.NewReProducer(targetProducer) |
||
| 159 | |||
| 160 | s := scan.NewScanner( |
||
| 161 | c, |
||
| 162 | targetProducer, |
||
| 163 | reproducer, |
||
| 164 | logger, |
||
| 165 | ) |
||
| 166 | |||
| 167 | logger.WithFields(logrus.Fields{ |
||
| 168 | "url": u.String(), |
||
| 169 | "threads": cnf.Threads, |
||
| 170 | "dictionary-length": len(dict), |
||
| 171 | "scan-depth": cnf.ScanDepth, |
||
| 172 | "timeout": cnf.TimeoutInMilliseconds, |
||
| 173 | "socks5": cnf.Socks5Url, |
||
| 174 | "cookies": strigifyCookies(cnf.Cookies), |
||
| 175 | "cookie-jar": cnf.UseCookieJar, |
||
| 176 | "headers": stringyfyHeaders(cnf.Headers), |
||
| 177 | "user-agent": cnf.UserAgent, |
||
| 178 | }).Info("Starting scan") |
||
| 179 | |||
| 180 | resultLogger := scan.NewResultLogger(logger) |
||
| 181 | summarizer := scan.NewResultSummarizer(logger.Out) |
||
| 182 | for result := range s.Scan(u, cnf.Threads) { |
||
| 183 | resultLogger.Log(result) |
||
| 184 | summarizer.Add(result) |
||
| 185 | } |
||
| 186 | |||
| 187 | summarizer.Summarize() |
||
| 188 | |||
| 189 | logger.Info("Finished scan") |
||
| 190 | |||
| 191 | return nil |
||
| 192 | } |
||
| 213 |