Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package settings | 5 package settings |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/base64" | 8 "encoding/base64" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "fmt" | 10 "fmt" |
| 11 "net/http" | 11 "net/http" |
| 12 "strconv" | |
| 12 | 13 |
| 13 ds "github.com/luci/gae/service/datastore" | 14 ds "github.com/luci/gae/service/datastore" |
| 14 "github.com/luci/luci-go/milo/api/resp" | 15 "github.com/luci/luci-go/milo/api/resp" |
| 15 "github.com/luci/luci-go/milo/appengine/model" | 16 "github.com/luci/luci-go/milo/appengine/model" |
| 17 "github.com/luci/luci-go/milo/common/miloerror" | |
| 16 "github.com/luci/luci-go/server/auth" | 18 "github.com/luci/luci-go/server/auth" |
| 17 "github.com/luci/luci-go/server/auth/identity" | 19 "github.com/luci/luci-go/server/auth/identity" |
| 18 "github.com/luci/luci-go/server/auth/xsrf" | 20 "github.com/luci/luci-go/server/auth/xsrf" |
| 19 "github.com/luci/luci-go/server/router" | 21 "github.com/luci/luci-go/server/router" |
| 20 | 22 |
| 21 "golang.org/x/net/context" | 23 "golang.org/x/net/context" |
| 22 ) | 24 ) |
| 23 | 25 |
| 24 type updateReq struct { | 26 type updateReq struct { |
| 25 Theme string | 27 Theme string |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 144 |
| 143 result := &resp.Settings{} | 145 result := &resp.Settings{} |
| 144 result.ActionURL = r.URL.String() | 146 result.ActionURL = r.URL.String() |
| 145 result.Theme = &resp.Choices{ | 147 result.Theme = &resp.Choices{ |
| 146 Choices: GetAllThemes(), | 148 Choices: GetAllThemes(), |
| 147 Selected: userSettings.Theme, | 149 Selected: userSettings.Theme, |
| 148 } | 150 } |
| 149 | 151 |
| 150 return result, nil | 152 return result, nil |
| 151 } | 153 } |
| 154 | |
| 155 // GetLimit extracts the "limit" http param from the request, or returns "-1" | |
| 156 // implying no limit was specified. | |
| 157 func GetLimit(r *http.Request) (int, error) { | |
|
nodir
2016/10/28 07:17:54
why this is in settings package? what does limit q
hinoka
2016/10/28 19:47:30
Technically nothing, i'm using the settings packag
nodir
2016/10/28 19:52:51
Perhaps this needs some refactoring. Go does not e
hinoka
2016/10/28 19:53:42
The alternative would be copypasta code...?
| |
| 158 sLimit := r.FormValue("limit") | |
|
nodir
2016/10/28 07:17:54
can you also fall back to "numBuilds"? this is wha
hinoka
2016/10/28 19:47:30
Done.
| |
| 159 if sLimit == "" { | |
| 160 return -1, nil | |
| 161 } | |
| 162 limit, err := strconv.Atoi(sLimit) | |
| 163 if err != nil { | |
| 164 return -1, &miloerror.Error{ | |
| 165 Message: fmt.Sprintf("limit parameter value %q is not a number: %s", sLimit, err), | |
| 166 Code: http.StatusBadRequest, | |
| 167 } | |
| 168 } | |
| 169 if limit < 0 { | |
| 170 return -1, &miloerror.Error{ | |
| 171 Message: fmt.Sprintf("limit parameter value %q is less t han 0", sLimit), | |
| 172 Code: http.StatusBadRequest, | |
| 173 } | |
| 174 } | |
| 175 return limit, nil | |
| 176 } | |
| OLD | NEW |