Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit cf66b40

Browse files
committed
refactor: remove deprecaded function
1 parent 53e3021 commit cf66b40

File tree

4 files changed

+14
-56
lines changed

4 files changed

+14
-56
lines changed

db.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ func (database *Database) add(w http.ResponseWriter, r *http.Request) {
6161
return
6262
}
6363

64-
_, r.URL.Path = ShiftPath(r.URL.Path)
65-
col, _ := ShiftPath(r.URL.Path)
64+
col := getURLPart(r.URL.Path, 2)
6665

6766
var v interface{}
6867
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -92,8 +91,7 @@ func (database *Database) bulkAdd(w http.ResponseWriter, r *http.Request) {
9291
return
9392
}
9493

95-
_, r.URL.Path = ShiftPath(r.URL.Path)
96-
col, _ := ShiftPath(r.URL.Path)
94+
col := getURLPart(r.URL.Path, 2)
9795

9896
var v []interface{}
9997
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -124,8 +122,7 @@ func (database *Database) list(w http.ResponseWriter, r *http.Request) {
124122
return
125123
}
126124

127-
_, r.URL.Path = ShiftPath(r.URL.Path)
128-
col, _ := ShiftPath(r.URL.Path)
125+
col := getURLPart(r.URL.Path, 2)
129126

130127
result, err := backend.DB.ListDocuments(auth, conf.Name, col, params)
131128
if err != nil {
@@ -143,11 +140,8 @@ func (database *Database) get(w http.ResponseWriter, r *http.Request) {
143140
return
144141
}
145142

146-
col, id := "", ""
147-
148-
_, r.URL.Path = ShiftPath(r.URL.Path)
149-
col, r.URL.Path = ShiftPath(r.URL.Path)
150-
id, r.URL.Path = ShiftPath(r.URL.Path)
143+
col := getURLPart(r.URL.Path, 2)
144+
id := getURLPart(r.URL.Path, 3)
151145

152146
result, err := backend.DB.GetDocumentByID(auth, conf.Name, col, id)
153147
if err != nil {
@@ -191,10 +185,7 @@ func (database *Database) query(w http.ResponseWriter, r *http.Request) {
191185
return
192186
}
193187

194-
var col string
195-
196-
_, r.URL.Path = ShiftPath(r.URL.Path)
197-
col, r.URL.Path = ShiftPath(r.URL.Path)
188+
col := getURLPart(r.URL.Path, 2)
198189

199190
result, err := backend.DB.QueryDocuments(auth, conf.Name, col, filter, params)
200191
if err != nil {
@@ -212,10 +203,7 @@ func (database *Database) getByIds(w http.ResponseWriter, r *http.Request) {
212203
return
213204
}
214205

215-
col := ""
216-
217-
_, r.URL.Path = ShiftPath(r.URL.Path)
218-
col, r.URL.Path = ShiftPath(r.URL.Path)
206+
col := getURLPart(r.URL.Path, 2)
219207

220208
var ids []string
221209
if err := parseBody(r.Body, &ids); err != nil {
@@ -244,11 +232,8 @@ func (database *Database) update(w http.ResponseWriter, r *http.Request) {
244232
return
245233
}
246234

247-
col, id := "", ""
248-
249-
_, r.URL.Path = ShiftPath(r.URL.Path)
250-
col, r.URL.Path = ShiftPath(r.URL.Path)
251-
id, r.URL.Path = ShiftPath(r.URL.Path)
235+
col := getURLPart(r.URL.Path, 2)
236+
id := getURLPart(r.URL.Path, 3)
252237

253238
var v interface{}
254239
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -278,10 +263,7 @@ func (database *Database) bulkUpdate(w http.ResponseWriter, r *http.Request) {
278263
return
279264
}
280265

281-
var col string
282-
283-
_, r.URL.Path = ShiftPath(r.URL.Path)
284-
col, r.URL.Path = ShiftPath(r.URL.Path)
266+
col := getURLPart(r.URL.Path, 2)
285267

286268
var v struct {
287269
UpdateFields map[string]any `json:"update"`
@@ -342,11 +324,8 @@ func (database *Database) del(w http.ResponseWriter, r *http.Request) {
342324
return
343325
}
344326

345-
col, id := "", ""
346-
347-
_, r.URL.Path = ShiftPath(r.URL.Path)
348-
col, r.URL.Path = ShiftPath(r.URL.Path)
349-
id, r.URL.Path = ShiftPath(r.URL.Path)
327+
col := getURLPart(r.URL.Path, 2)
328+
id := getURLPart(r.URL.Path, 3)
350329

351330
count, err := backend.DB.DeleteDocument(auth, conf.Name, col, id)
352331
if err != nil {

form.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ func submitForm(w http.ResponseWriter, r *http.Request) {
1515
return
1616
}
1717

18-
form := ""
19-
20-
_, r.URL.Path = ShiftPath(r.URL.Path)
21-
form, r.URL.Path = ShiftPath(r.URL.Path)
18+
form := getURLPart(r.URL.Path, 2)
2219

2320
doc := make(map[string]interface{})
2421

membership.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ func (m *membership) sudoGetTokenFromAccountID(w http.ResponseWriter, r *http.Re
197197
return
198198
}
199199

200-
id := ""
201-
202-
_, r.URL.Path = ShiftPath(r.URL.Path)
203-
id, r.URL.Path = ShiftPath(r.URL.Path)
200+
id := getURLPart(r.URL.Path, 3)
204201

205202
tok, err := backend.DB.GetFirstUserFromAccountID(conf.Name, id)
206203
if err != nil {

url.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)