Conditions | 3 |
Total Lines | 58 |
Code Lines | 43 |
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 scan |
||
16 | func StartScan(logger *logrus.Logger, eventManager *emission.Emitter, cnf *Config, u *url.URL) error { |
||
17 | c, err := client.NewClientFromConfig( |
||
18 | cnf.TimeoutInMilliseconds, |
||
19 | cnf.Socks5Url, |
||
20 | cnf.UserAgent, |
||
21 | cnf.UseCookieJar, |
||
22 | cnf.Cookies, |
||
23 | cnf.Headers, |
||
24 | u, |
||
25 | ) |
||
26 | if err != nil { |
||
27 | return errors.Wrap(err, "failed to build client") |
||
28 | } |
||
29 | |||
30 | s := NewScanner( |
||
31 | c, |
||
32 | eventManager, |
||
33 | logger, |
||
34 | ) |
||
35 | |||
36 | dict, err := dictionary.NewDictionaryFrom(cnf.DictionaryPath, c) |
||
37 | if err != nil { |
||
38 | return errors.Wrap(err, "failed to build dictionary") |
||
39 | } |
||
40 | |||
41 | r := NewReProcessor(eventManager, cnf.HTTPMethods, dict) |
||
42 | |||
43 | eventManager.On(EventResultFound, r.ReProcess) |
||
44 | eventManager.On(EventTargetProduced, s.AddTarget) |
||
45 | eventManager.On(EventProducerFinished, s.Release) |
||
46 | |||
47 | targetProducer := NewTargetProducer( |
||
48 | eventManager, |
||
49 | cnf.HTTPMethods, |
||
50 | dict, |
||
51 | cnf.ScanDepth, |
||
52 | ) |
||
53 | |||
54 | go targetProducer.Run() |
||
55 | |||
56 | logger.WithFields(logrus.Fields{ |
||
57 | "url": u.String(), |
||
58 | "threads": cnf.Threads, |
||
59 | "dictionary-length": len(dict), |
||
60 | "scan-depth": cnf.ScanDepth, |
||
61 | "timeout": cnf.TimeoutInMilliseconds, |
||
62 | "socks5": cnf.Socks5Url, |
||
63 | "cookies": strigifyCookies(cnf.Cookies), |
||
64 | "cookie-jar": cnf.UseCookieJar, |
||
65 | "headers": stringyfyHeaders(cnf.Headers), |
||
66 | "user-agent": cnf.UserAgent, |
||
67 | }).Info("Starting scan") |
||
68 | |||
69 | s.Scan(u, cnf.Threads) |
||
70 | |||
71 | logger.Info("Finished scan") |
||
72 | |||
73 | return nil |
||
74 | } |
||
95 |