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