-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.go
59 lines (48 loc) · 1.5 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package auth
import (
"encoding/json"
"net/http"
"strings"
)
// UpdateSettings document: http://kidstuff.github.io/swagger/#!/default/settings_patch
func UpdateSettings(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error) {
settings := map[string]string{}
err := json.NewDecoder(req.Body).Decode(&settings)
req.Body.Close()
if err != nil {
return http.StatusBadRequest, err
}
err = ctx.Settings.SetMulti(settings)
if err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}
// GetSettings document: http://kidstuff.github.io/swagger/#!/default/settings_get
func GetSettings(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error) {
keys := strings.Split(req.FormValue("keys"), ",")
if len(keys) == 0 {
return http.StatusBadRequest, ErrNoKeyProvided
}
settings, err := ctx.Settings.GetMulti(keys)
if err != nil {
return http.StatusInternalServerError, err
}
err = json.NewEncoder(rw).Encode(settings)
if err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}
// DeleteSettings document: http://kidstuff.github.io/swagger/#!/default/settings_delete
func DeleteSettings(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error) {
keys := strings.Split(req.FormValue("keys"), ",")
if len(keys) == 0 {
return http.StatusBadRequest, ErrNoKeyProvided
}
err := ctx.Settings.UnSetMulti(keys)
if err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}