Conditions | 6 |
Total Lines | 61 |
Code Lines | 37 |
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 main |
||
55 | func main() { |
||
56 | fmt.Printf("planfix-toggl %s\n", version) |
||
57 | |||
58 | cfg := config.GetConfig() |
||
59 | |||
60 | parseFlags(&cfg) |
||
61 | |||
62 | logger := getLogger(cfg) |
||
63 | |||
64 | if cfg.SMTPSecure { |
||
65 | err := "[ERROR] Secure SMTP not implemented" |
||
66 | logger.Fatal(err) |
||
67 | os.Exit(1) |
||
68 | } |
||
69 | |||
70 | if cfg.NoConsole { |
||
71 | util.HideConsole() |
||
72 | } |
||
73 | |||
74 | // create planfix client |
||
75 | planfixAPI := planfix.New( |
||
76 | cfg.PlanfixAPIUrl, |
||
77 | cfg.PlanfixAPIKey, |
||
78 | cfg.PlanfixAccount, |
||
79 | cfg.PlanfixUserName, |
||
80 | cfg.PlanfixUserPassword, |
||
81 | ) |
||
82 | if !cfg.Debug { |
||
83 | planfixAPI.Logger.SetFlags(0) |
||
84 | planfixAPI.Logger.SetOutput(ioutil.Discard) |
||
85 | } |
||
86 | planfixAPI.UserAgent = "planfix-toggl" |
||
87 | |||
88 | // create toggl client |
||
89 | togglClient := client.TogglClient{ |
||
90 | Session: toggl.OpenSession(cfg.TogglAPIToken), |
||
91 | Config: &cfg, |
||
92 | PlanfixAPI: planfixAPI, |
||
93 | Logger: logger, |
||
94 | } |
||
95 | |||
96 | // get planfix and toggl user IDs, for early API check |
||
97 | if cfg.PlanfixUserName != "" && cfg.PlanfixUserPassword != "" { |
||
98 | cfg.PlanfixUserID = togglClient.GetPlanfixUserID() |
||
99 | } |
||
100 | cfg.TogglUserID = togglClient.GetTogglUserID() |
||
101 | |||
102 | // start tag cleaner |
||
103 | go togglClient.RunTagCleaner() |
||
104 | |||
105 | // start sender |
||
106 | go togglClient.RunSender() |
||
107 | |||
108 | // start API server |
||
109 | server := rest.Server{ |
||
110 | Version: version, |
||
111 | TogglClient: togglClient, |
||
112 | Config: cfg, |
||
113 | Logger: logger, |
||
114 | } |
||
115 | server.Run() |
||
116 | } |
||
117 |