chore: style fixes from go fix (#10846)
Just `go fix ./...` Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
+15
-15
@@ -202,7 +202,7 @@ func (s *service) getListener(guiCfg config.GUIConfiguration) (net.Listener, err
|
||||
return listener, nil
|
||||
}
|
||||
|
||||
func sendJSON(w http.ResponseWriter, jsonObject interface{}) {
|
||||
func sendJSON(w http.ResponseWriter, jsonObject any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
// Marshalling might fail, in which case we should return a 500 with the
|
||||
// actual error.
|
||||
@@ -696,7 +696,7 @@ func (*service) getSystemPaths(w http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
|
||||
func (s *service) getJSMetadata(w http.ResponseWriter, _ *http.Request) {
|
||||
meta, _ := json.Marshal(map[string]interface{}{
|
||||
meta, _ := json.Marshal(map[string]any{
|
||||
"deviceID": s.id.String(),
|
||||
"deviceIDShort": s.id.Short().String(),
|
||||
"authenticated": true,
|
||||
@@ -706,7 +706,7 @@ func (s *service) getJSMetadata(w http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
|
||||
func (*service) getSystemVersion(w http.ResponseWriter, _ *http.Request) {
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"version": build.Version,
|
||||
"codename": build.Codename,
|
||||
"longVersion": build.LongVersion,
|
||||
@@ -838,7 +838,7 @@ func (s *service) getDBNeed(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Convert the struct to a more loose structure, and inject the size.
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"progress": toJsonFileInfoSlice(progress),
|
||||
"queued": toJsonFileInfoSlice(queued),
|
||||
"rest": toJsonFileInfoSlice(rest),
|
||||
@@ -866,7 +866,7 @@ func (s *service) getDBRemoteNeed(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"files": toJsonFileInfoSlice(files),
|
||||
"page": page,
|
||||
"perpage": perpage,
|
||||
@@ -886,7 +886,7 @@ func (s *service) getDBLocalChanged(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"files": toJsonFileInfoSlice(files),
|
||||
"page": page,
|
||||
"perpage": perpage,
|
||||
@@ -951,7 +951,7 @@ func (s *service) getDBFile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"global": jsonFileInfo(gf),
|
||||
"local": jsonFileInfo(lf),
|
||||
"availability": av,
|
||||
@@ -967,7 +967,7 @@ func (s *service) getDebugFile(w http.ResponseWriter, r *http.Request) {
|
||||
gf, _, _ := s.model.CurrentGlobalFile(folder, file)
|
||||
av, _ := s.model.Availability(folder, protocol.FileInfo{Name: file}, protocol.BlockInfo{})
|
||||
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"global": jsonFileInfo(gf),
|
||||
"local": jsonFileInfo(lf),
|
||||
"availability": av,
|
||||
@@ -1037,7 +1037,7 @@ func (s *service) getSystemStatus(w http.ResponseWriter, _ *http.Request) {
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
tilde, _ := fs.ExpandTilde("~")
|
||||
res := make(map[string]interface{})
|
||||
res := make(map[string]any)
|
||||
res["myID"] = s.id.String()
|
||||
res["goroutines"] = runtime.NumGoroutine()
|
||||
res["alloc"] = m.Alloc
|
||||
@@ -1302,7 +1302,7 @@ func (s *service) getDBIgnores(w http.ResponseWriter, r *http.Request) {
|
||||
folder := qs.Get("folder")
|
||||
|
||||
lines, patterns, err := s.model.LoadIgnores(folder)
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"ignore": lines,
|
||||
"expanded": patterns,
|
||||
"error": errorString(err),
|
||||
@@ -1411,7 +1411,7 @@ func (s *service) getSystemUpgrade(w http.ResponseWriter, _ *http.Request) {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
res := make(map[string]interface{})
|
||||
res := make(map[string]any)
|
||||
res["running"] = build.Version
|
||||
res["latest"] = rel.Tag
|
||||
res["newer"] = upgrade.CompareVersions(rel.Tag, build.Version) == upgrade.Newer
|
||||
@@ -1439,7 +1439,7 @@ func (*service) getDeviceID(w http.ResponseWriter, r *http.Request) {
|
||||
func (*service) getLang(w http.ResponseWriter, r *http.Request) {
|
||||
lang := r.Header.Get("Accept-Language")
|
||||
weights := make(map[string]float64)
|
||||
for _, l := range strings.Split(lang, ",") {
|
||||
for l := range strings.SplitSeq(lang, ",") {
|
||||
parts := strings.SplitN(l, ";", 2)
|
||||
code := strings.ToLower(strings.TrimSpace(parts[0]))
|
||||
weights[code] = 1.0
|
||||
@@ -1638,7 +1638,7 @@ func (s *service) getFolderErrors(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
sendJSON(w, map[string]interface{}{
|
||||
sendJSON(w, map[string]any{
|
||||
"folder": folder,
|
||||
"errors": errors,
|
||||
"page": page,
|
||||
@@ -1770,8 +1770,8 @@ func (f jsonFileInfo) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
func fileIntfJSONMap(f protocol.FileInfo) map[string]interface{} {
|
||||
out := map[string]interface{}{
|
||||
func fileIntfJSONMap(f protocol.FileInfo) map[string]any {
|
||||
out := map[string]any{
|
||||
"name": f.FileName(),
|
||||
"type": f.FileType().String(),
|
||||
"size": f.Size,
|
||||
|
||||
+1
-4
@@ -311,10 +311,7 @@ func authLDAP(username string, password string, cfg config.LDAPConfiguration) bo
|
||||
|
||||
func formatOptionalPercentS(template string, username string) string {
|
||||
var replacements []any
|
||||
nReps := strings.Count(template, "%s") - strings.Count(template, "%%s")
|
||||
if nReps < 0 {
|
||||
nReps = 0
|
||||
}
|
||||
nReps := max(strings.Count(template, "%s")-strings.Count(template, "%%s"), 0)
|
||||
for range nReps {
|
||||
replacements = append(replacements, username)
|
||||
}
|
||||
|
||||
+1
-2
@@ -433,7 +433,6 @@ func TestAPIServiceRequests(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.URL, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testHTTPRequest(t, baseURL, tc, testAPIKey)
|
||||
@@ -1723,7 +1722,7 @@ func TestConfigChanges(t *testing.T) {
|
||||
return resp
|
||||
}
|
||||
|
||||
mod := func(method, path string, data interface{}) {
|
||||
mod := func(method, path string, data any) {
|
||||
t.Helper()
|
||||
bs, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:build noassets
|
||||
// +build noassets
|
||||
|
||||
package auto
|
||||
|
||||
|
||||
@@ -441,7 +441,7 @@ func (c *configMuxBuilder) adjustLDAP(w http.ResponseWriter, r *http.Request, ld
|
||||
}
|
||||
|
||||
// Unmarshals the content of the given body and stores it in to (i.e. to must be a pointer).
|
||||
func unmarshalTo(body io.ReadCloser, to interface{}) error {
|
||||
func unmarshalTo(body io.ReadCloser, to any) error {
|
||||
bs, err := io.ReadAll(body)
|
||||
body.Close()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user