Conditions | 10 |
Total Lines | 58 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 11.2294 |
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:
Complex classes like main.main often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | // Copyright 2018 Fedir RYKHTIK. All rights reserved. |
||
17 | func main() { |
||
18 | 1 | var ( |
|
19 | clearHTTPCache = flag.Bool("cc", false, "Clear HTTP cache") |
||
20 | clearHTTPCacheDryRun = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)") |
||
21 | debug = flag.Bool("d", false, "Debug mode") |
||
22 | resultFileSavePath = flag.String("f", "", "File path where result CSV file will be saved") |
||
23 | rateLimitCheck = flag.Bool("l", false, "Rate limit check") |
||
24 | repositoriesKeysManual = flag.String("r", "", "Repositories keys") |
||
25 | tmpFolder = flag.String("t", "test_data", "Temporary folder path") |
||
26 | repositoriesKeys = []string{} |
||
27 | ) |
||
28 | 1 | flag.Parse() |
|
29 | 1 | if *clearHTTPCache || *clearHTTPCacheDryRun { |
|
30 | clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun) |
||
31 | os.Exit(0) |
||
32 | } |
||
33 | 1 | if *rateLimitCheck { |
|
34 | github.CheckAndPrintRateLimit() |
||
35 | os.Exit(0) |
||
36 | } |
||
37 | 1 | if *repositoriesKeysManual != "" { |
|
38 | repositoriesKeys = uniqSlice(strings.Split(*repositoriesKeysManual, ",")) |
||
39 | } else { |
||
40 | 1 | repositoriesKeys = uniqSlice([]string{ |
|
41 | "astaxie/beego", |
||
42 | "gohugoio/hugo", |
||
43 | "gin-gonic/gin", |
||
44 | "labstack/echo", |
||
45 | "revel/revel", |
||
46 | "gobuffalo/buffalo", |
||
47 | "go-chi/chi", |
||
48 | "kataras/iris", |
||
49 | "zenazn/goji", |
||
50 | "go-macaron/macaron", |
||
51 | "go-aah/aah", |
||
52 | }) |
||
53 | } |
||
54 | |||
55 | 1 | csvFilePath := "" |
|
56 | 1 | if *resultFileSavePath != "" { |
|
57 | csvFilePath = *resultFileSavePath |
||
58 | } else { |
||
59 | 1 | csvFilePath = "result.csv" |
|
60 | } |
||
61 | 1 | var ghData = []Repository{} |
|
62 | 1 | var wg sync.WaitGroup |
|
63 | 1 | wg.Add(len(repositoriesKeys)) |
|
64 | |||
65 | 1 | dataChan := make(chan Repository, len(repositoriesKeys)) |
|
66 | 1 | for _, rKey := range repositoriesKeys { |
|
67 | 1 | go repositoryData(rKey, *tmpFolder, *debug, dataChan, &wg) |
|
68 | } |
||
69 | 1 | for range repositoriesKeys { |
|
70 | 1 | ghData = append(ghData, <-dataChan) |
|
71 | } |
||
72 | 1 | wg.Wait() |
|
73 | 1 | rateAndPrintGreetings(ghData) |
|
74 | 1 | writeCSVStatistics(ghData, csvFilePath) |
|
75 | } |
||
90 |