Skip to content

Commit f0a9ab8

Browse files
committed
refactor: Fixing golang-ci, fieldalignment and complexity
Signed-off-by: Vincent Boutour <[email protected]>
1 parent 279443b commit f0a9ab8

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

pkg/crud/post.go

+42-29
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,13 @@ func (a *App) Post(w http.ResponseWriter, r *http.Request, request provider.Requ
4949
if contentType == "application/x-www-form-urlencoded" {
5050
method := r.FormValue("method")
5151

52-
if r.FormValue("type") == "share" {
53-
switch method {
54-
case http.MethodPost:
55-
a.createShare(w, r, request)
56-
case http.MethodDelete:
57-
a.deleteShare(w, r, request)
58-
default:
59-
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown share method `%s` for %s", method, r.URL.Path)))
60-
}
61-
} else if r.FormValue("type") == "webhook" {
62-
switch method {
63-
case http.MethodPost:
64-
a.createWebhook(w, r, request)
65-
case http.MethodDelete:
66-
a.deleteWebhook(w, r, request)
67-
default:
68-
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown webhook method `%s` for %s", method, r.URL.Path)))
69-
}
70-
} else {
71-
switch method {
72-
case http.MethodPatch:
73-
a.Rename(w, r, request)
74-
case http.MethodPut:
75-
a.Create(w, r, request)
76-
case http.MethodDelete:
77-
a.Delete(w, r, request)
78-
default:
79-
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown method `%s` for %s", method, r.URL.Path)))
80-
}
52+
switch r.FormValue("type") {
53+
case "share":
54+
a.handlePostShare(w, r, request, method)
55+
case "webhook":
56+
a.handlePostWebhook(w, r, request, method)
57+
default:
58+
a.handlePost(w, r, request, method)
8159
}
8260

8361
return
@@ -101,3 +79,38 @@ func (a *App) Post(w http.ResponseWriter, r *http.Request, request provider.Requ
10179

10280
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown content-type %s", contentType)))
10381
}
82+
83+
func (a *App) handlePostShare(w http.ResponseWriter, r *http.Request, request provider.Request, method string) {
84+
switch method {
85+
case http.MethodPost:
86+
a.createShare(w, r, request)
87+
case http.MethodDelete:
88+
a.deleteShare(w, r, request)
89+
default:
90+
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown share method `%s` for %s", method, r.URL.Path)))
91+
}
92+
}
93+
94+
func (a *App) handlePostWebhook(w http.ResponseWriter, r *http.Request, request provider.Request, method string) {
95+
switch method {
96+
case http.MethodPost:
97+
a.createWebhook(w, r, request)
98+
case http.MethodDelete:
99+
a.deleteWebhook(w, r, request)
100+
default:
101+
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown webhook method `%s` for %s", method, r.URL.Path)))
102+
}
103+
}
104+
105+
func (a *App) handlePost(w http.ResponseWriter, r *http.Request, request provider.Request, method string) {
106+
switch method {
107+
case http.MethodPatch:
108+
a.Rename(w, r, request)
109+
case http.MethodPut:
110+
a.Create(w, r, request)
111+
case http.MethodDelete:
112+
a.Delete(w, r, request)
113+
default:
114+
a.rendererApp.Error(w, model.WrapMethodNotAllowed(fmt.Errorf("unknown method `%s` for %s", method, r.URL.Path)))
115+
}
116+
}

pkg/exif/exif.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ var (
5757
type App struct {
5858
storageApp provider.Storage
5959

60-
done chan struct{}
61-
geocodeQueue chan provider.StorageItem
62-
aggregateQueue chan provider.StorageItem
60+
done chan struct{}
61+
geocodeQueue chan provider.StorageItem
6362

6463
metrics map[string]*prometheus.GaugeVec
6564

pkg/exif/geocode.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ func convertDegreeMinuteSecondToDecimal(location string) (string, error) {
161161

162162
match := matches[0]
163163

164-
degrees, err := strconv.ParseFloat(match[1], 16)
164+
degrees, err := strconv.ParseFloat(match[1], 32)
165165
if err != nil {
166166
return "", fmt.Errorf("unable to parse GPS degrees: %s", err)
167167
}
168168

169-
minutes, err := strconv.ParseFloat(match[2], 16)
169+
minutes, err := strconv.ParseFloat(match[2], 32)
170170
if err != nil {
171171
return "", fmt.Errorf("unable to parse GPS minutes: %s", err)
172172
}
173173

174-
seconds, err := strconv.ParseFloat(match[3], 16)
174+
seconds, err := strconv.ParseFloat(match[3], 32)
175175
if err != nil {
176176
return "", fmt.Errorf("unable to parse GPS seconds: %s", err)
177177
}

pkg/exif/model.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ func (a locationAggregate) inc(key, value string) {
2020
}
2121

2222
if level, ok := a[key]; ok {
23-
if _, ok := level[value]; ok {
24-
level[value]++
25-
} else {
26-
level[value] = 1
27-
}
23+
level[value]++
2824
} else {
2925
a[key] = map[string]int64{
3026
value: 1,

pkg/provider/event.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (et EventType) MarshalJSON() ([]byte, error) {
4949

5050
// Event describes an event on fibr
5151
type Event struct {
52-
Item StorageItem `json:"item"`
5352
New *StorageItem `json:"new,omitempty"`
53+
Item StorageItem `json:"item"`
5454
Type EventType `json:"type"`
5555
}
5656

0 commit comments

Comments
 (0)