refactor: run Go modernize (#5002)
This commit is contained in:
+3
-3
@@ -68,8 +68,8 @@ func doLogin(ds model.DataStore, username string, password string, w http.Respon
|
||||
_ = rest.RespondWithJSON(w, http.StatusOK, payload)
|
||||
}
|
||||
|
||||
func buildAuthPayload(user *model.User) map[string]interface{} {
|
||||
payload := map[string]interface{}{
|
||||
func buildAuthPayload(user *model.User) map[string]any {
|
||||
payload := map[string]any{
|
||||
"id": user.ID,
|
||||
"name": user.Name,
|
||||
"username": user.UserName,
|
||||
@@ -288,7 +288,7 @@ func JWTRefresher(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func handleLoginFromHeaders(ds model.DataStore, r *http.Request) map[string]interface{} {
|
||||
func handleLoginFromHeaders(ds model.DataStore, r *http.Request) map[string]any {
|
||||
username := UsernameFromConfig(r)
|
||||
if username == "" {
|
||||
username = UsernameFromExtAuthHeader(r)
|
||||
|
||||
+7
-7
@@ -53,7 +53,7 @@ var _ = Describe("Auth", func() {
|
||||
|
||||
It("returns the expected payload", func() {
|
||||
Expect(resp.Code).To(Equal(http.StatusOK))
|
||||
var parsed map[string]interface{}
|
||||
var parsed map[string]any
|
||||
Expect(json.Unmarshal(resp.Body.Bytes(), &parsed)).To(BeNil())
|
||||
Expect(parsed["isAdmin"]).To(Equal(true))
|
||||
Expect(parsed["username"]).To(Equal("johndoe"))
|
||||
@@ -88,7 +88,7 @@ var _ = Describe("Auth", func() {
|
||||
serveIndex(ds, fs, nil)(resp, req)
|
||||
|
||||
config := extractAppConfig(resp.Body.String())
|
||||
parsed := config["auth"].(map[string]interface{})
|
||||
parsed := config["auth"].(map[string]any)
|
||||
|
||||
Expect(parsed["id"]).To(Equal("111"))
|
||||
})
|
||||
@@ -106,7 +106,7 @@ var _ = Describe("Auth", func() {
|
||||
serveIndex(ds, fs, nil)(resp, req)
|
||||
|
||||
config := extractAppConfig(resp.Body.String())
|
||||
parsed := config["auth"].(map[string]interface{})
|
||||
parsed := config["auth"].(map[string]any)
|
||||
|
||||
Expect(parsed["id"]).To(Equal("111"))
|
||||
})
|
||||
@@ -127,7 +127,7 @@ var _ = Describe("Auth", func() {
|
||||
serveIndex(ds, fs, nil)(resp, req)
|
||||
|
||||
config := extractAppConfig(resp.Body.String())
|
||||
parsed := config["auth"].(map[string]interface{})
|
||||
parsed := config["auth"].(map[string]any)
|
||||
|
||||
Expect(parsed["username"]).To(Equal(newUser))
|
||||
})
|
||||
@@ -137,7 +137,7 @@ var _ = Describe("Auth", func() {
|
||||
serveIndex(ds, fs, nil)(resp, req)
|
||||
|
||||
config := extractAppConfig(resp.Body.String())
|
||||
parsed := config["auth"].(map[string]interface{})
|
||||
parsed := config["auth"].(map[string]any)
|
||||
|
||||
Expect(parsed["id"]).To(Equal("111"))
|
||||
Expect(parsed["isAdmin"]).To(BeFalse())
|
||||
@@ -182,7 +182,7 @@ var _ = Describe("Auth", func() {
|
||||
serveIndex(ds, fs, nil)(resp, req)
|
||||
|
||||
config := extractAppConfig(resp.Body.String())
|
||||
parsed := config["auth"].(map[string]interface{})
|
||||
parsed := config["auth"].(map[string]any)
|
||||
|
||||
Expect(parsed["id"]).To(Equal("111"))
|
||||
})
|
||||
@@ -206,7 +206,7 @@ var _ = Describe("Auth", func() {
|
||||
login(ds)(resp, req)
|
||||
Expect(resp.Code).To(Equal(http.StatusOK))
|
||||
|
||||
var parsed map[string]interface{}
|
||||
var parsed map[string]any
|
||||
Expect(json.Unmarshal(resp.Body.Bytes(), &parsed)).To(BeNil())
|
||||
Expect(parsed["isAdmin"]).To(Equal(false))
|
||||
Expect(parsed["username"]).To(Equal("janedoe"))
|
||||
|
||||
@@ -37,7 +37,7 @@ func requestLogger(next http.Handler) http.Handler {
|
||||
status := ww.Status()
|
||||
|
||||
message := fmt.Sprintf("HTTP: %s %s://%s%s", r.Method, scheme, r.Host, r.RequestURI)
|
||||
logArgs := []interface{}{
|
||||
logArgs := []any{
|
||||
r.Context(),
|
||||
message,
|
||||
"remoteAddr", r.RemoteAddr,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
@@ -35,9 +36,9 @@ var sensitiveFieldsFullMask = []string{
|
||||
}
|
||||
|
||||
type configResponse struct {
|
||||
ID string `json:"id"`
|
||||
ConfigFile string `json:"configFile"`
|
||||
Config map[string]interface{} `json:"config"`
|
||||
ID string `json:"id"`
|
||||
ConfigFile string `json:"configFile"`
|
||||
Config map[string]any `json:"config"`
|
||||
}
|
||||
|
||||
func redactValue(key string, value string) string {
|
||||
@@ -47,10 +48,8 @@ func redactValue(key string, value string) string {
|
||||
}
|
||||
|
||||
// Check if this field should be fully masked
|
||||
for _, field := range sensitiveFieldsFullMask {
|
||||
if field == key {
|
||||
return "****"
|
||||
}
|
||||
if slices.Contains(sensitiveFieldsFullMask, key) {
|
||||
return "****"
|
||||
}
|
||||
|
||||
// Check if this field should be partially masked
|
||||
@@ -69,7 +68,7 @@ func redactValue(key string, value string) string {
|
||||
}
|
||||
|
||||
// applySensitiveFieldMasking recursively applies masking to sensitive fields in the configuration map
|
||||
func applySensitiveFieldMasking(ctx context.Context, config map[string]interface{}, prefix string) {
|
||||
func applySensitiveFieldMasking(ctx context.Context, config map[string]any, prefix string) {
|
||||
for key, value := range config {
|
||||
fullKey := key
|
||||
if prefix != "" {
|
||||
@@ -77,7 +76,7 @@ func applySensitiveFieldMasking(ctx context.Context, config map[string]interface
|
||||
}
|
||||
|
||||
switch v := value.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
// Recursively process nested maps
|
||||
applySensitiveFieldMasking(ctx, v, fullKey)
|
||||
case string:
|
||||
@@ -108,7 +107,7 @@ func getConfig(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Unmarshal back to map to get the structure with proper field names
|
||||
var configMap map[string]interface{}
|
||||
var configMap map[string]any
|
||||
err = json.Unmarshal(configBytes, &configMap)
|
||||
if err != nil {
|
||||
log.Error(ctx, "Error unmarshaling config to map", err)
|
||||
|
||||
@@ -93,12 +93,12 @@ var _ = Describe("Config API", func() {
|
||||
Expect(json.Unmarshal(w.Body.Bytes(), &resp)).To(Succeed())
|
||||
|
||||
// Check LastFM.ApiKey (partially masked)
|
||||
lastfm, ok := resp.Config["LastFM"].(map[string]interface{})
|
||||
lastfm, ok := resp.Config["LastFM"].(map[string]any)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(lastfm["ApiKey"]).To(Equal("s*************3"))
|
||||
|
||||
// Check Spotify.Secret (partially masked)
|
||||
spotify, ok := resp.Config["Spotify"].(map[string]interface{})
|
||||
spotify, ok := resp.Config["Spotify"].(map[string]any)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(spotify["Secret"]).To(Equal("s**************6"))
|
||||
|
||||
@@ -109,7 +109,7 @@ var _ = Describe("Config API", func() {
|
||||
Expect(resp.Config["DevAutoCreateAdminPassword"]).To(Equal("****"))
|
||||
|
||||
// Check Prometheus.Password (fully masked)
|
||||
prometheus, ok := resp.Config["Prometheus"].(map[string]interface{})
|
||||
prometheus, ok := resp.Config["Prometheus"].(map[string]any)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(prometheus["Password"]).To(Equal("****"))
|
||||
})
|
||||
@@ -128,7 +128,7 @@ var _ = Describe("Config API", func() {
|
||||
Expect(json.Unmarshal(w.Body.Bytes(), &resp)).To(Succeed())
|
||||
|
||||
// Check LastFM.ApiKey - should be preserved because it's sensitive
|
||||
lastfm, ok := resp.Config["LastFM"].(map[string]interface{})
|
||||
lastfm, ok := resp.Config["LastFM"].(map[string]any)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(lastfm["ApiKey"]).To(Equal(""))
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func (api *Router) routes() http.Handler {
|
||||
return r
|
||||
}
|
||||
|
||||
func (api *Router) R(r chi.Router, pathPrefix string, model interface{}, persistable bool) {
|
||||
func (api *Router) R(r chi.Router, pathPrefix string, model any, persistable bool) {
|
||||
constructor := func(ctx context.Context) rest.Repository {
|
||||
return api.ds.Resource(ctx, model)
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func reorderItem(ds model.DataStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = w.Write([]byte(fmt.Sprintf(`{"id":"%d"}`, id)))
|
||||
_, err = w.Write(fmt.Appendf(nil, `{"id":"%d"}`, id))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func newTranslationRepository(context.Context) rest.Repository {
|
||||
|
||||
type translationRepository struct{}
|
||||
|
||||
func (r *translationRepository) Read(id string) (interface{}, error) {
|
||||
func (r *translationRepository) Read(id string) (any, error) {
|
||||
translations, _ := loadTranslations()
|
||||
if t, ok := translations[id]; ok {
|
||||
return t, nil
|
||||
@@ -43,7 +43,7 @@ func (r *translationRepository) Count(...rest.QueryOptions) (int64, error) {
|
||||
}
|
||||
|
||||
// ReadAll simple implementation, only returns IDs. Does not support any `options`
|
||||
func (r *translationRepository) ReadAll(...rest.QueryOptions) (interface{}, error) {
|
||||
func (r *translationRepository) ReadAll(...rest.QueryOptions) (any, error) {
|
||||
translations, _ := loadTranslations()
|
||||
var result []translation
|
||||
for _, t := range translations {
|
||||
@@ -57,7 +57,7 @@ func (r *translationRepository) EntityName() string {
|
||||
return "translation"
|
||||
}
|
||||
|
||||
func (r *translationRepository) NewInstance() interface{} {
|
||||
func (r *translationRepository) NewInstance() any {
|
||||
return &translation{}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func loadTranslation(fsys fs.FS, fileName string) (translation translation, err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var out map[string]interface{}
|
||||
var out map[string]any
|
||||
if err = json.Unmarshal(data, &out); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ var _ = Describe("Translations", func() {
|
||||
filePath := filepath.Join(consts.I18nFolder, name)
|
||||
file, _ := fsys.Open(filePath)
|
||||
data, _ := io.ReadAll(file)
|
||||
var out map[string]interface{}
|
||||
var out map[string]any
|
||||
|
||||
Expect(filepath.Ext(filePath)).To(Equal(".json"), filePath)
|
||||
Expect(json.Unmarshal(data, &out)).To(BeNil(), filePath)
|
||||
@@ -40,7 +40,7 @@ var _ = Describe("Translations", func() {
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tr.ID).To(Equal("en"))
|
||||
Expect(tr.Name).To(Equal("English"))
|
||||
var out map[string]interface{}
|
||||
var out map[string]any
|
||||
Expect(json.Unmarshal([]byte(tr.Data), &out)).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -39,7 +39,7 @@ func serveIndex(ds model.DataStore, fs fs.FS, shareInfo *model.Share) http.Handl
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
appConfig := map[string]interface{}{
|
||||
appConfig := map[string]any{
|
||||
"version": consts.Version,
|
||||
"firstTime": firstTime,
|
||||
"variousArtistsId": consts.VariousArtistsID,
|
||||
@@ -95,7 +95,7 @@ func serveIndex(ds model.DataStore, fs fs.FS, shareInfo *model.Share) http.Handl
|
||||
if version != "dev" {
|
||||
version = "v" + version
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"AppConfig": string(appConfigJson),
|
||||
"Version": version,
|
||||
}
|
||||
@@ -145,7 +145,7 @@ type shareTrack struct {
|
||||
Duration float32 `json:"duration,omitempty"`
|
||||
}
|
||||
|
||||
func addShareData(r *http.Request, data map[string]interface{}, shareInfo *model.Share) {
|
||||
func addShareData(r *http.Request, data map[string]any, shareInfo *model.Share) {
|
||||
ctx := r.Context()
|
||||
if shareInfo == nil || shareInfo.ID == "" {
|
||||
return
|
||||
|
||||
+2
-2
@@ -80,8 +80,8 @@ func (s *Server) Run(ctx context.Context, addr string, port int, tlsCert string,
|
||||
// Create a listener based on the address type (either Unix socket or TCP)
|
||||
var listener net.Listener
|
||||
var err error
|
||||
if strings.HasPrefix(addr, "unix:") {
|
||||
socketPath := strings.TrimPrefix(addr, "unix:")
|
||||
if after, ok := strings.CutPrefix(addr, "unix:"); ok {
|
||||
socketPath := after
|
||||
listener, err = createUnixSocketFile(socketPath, conf.Server.UnixSocketPerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -319,7 +319,7 @@ func sendResponse(w http.ResponseWriter, r *http.Request, payload *responses.Sub
|
||||
callback, _ := p.String("callback")
|
||||
wrapper := &responses.JsonWrapper{Subsonic: *payload}
|
||||
response, err = json.Marshal(wrapper)
|
||||
response = []byte(fmt.Sprintf("%s(%s)", callback, response))
|
||||
response = fmt.Appendf(nil, "%s(%s)", callback, response)
|
||||
default:
|
||||
w.Header().Set("Content-Type", "application/xml")
|
||||
response, err = xml.Marshal(payload)
|
||||
|
||||
@@ -34,10 +34,10 @@ func newResponse() *responses.Subsonic {
|
||||
|
||||
type subError struct {
|
||||
code int32
|
||||
messages []interface{}
|
||||
messages []any
|
||||
}
|
||||
|
||||
func newError(code int32, message ...interface{}) error {
|
||||
func newError(code int32, message ...any) error {
|
||||
return subError{
|
||||
code: code,
|
||||
messages: message,
|
||||
@@ -176,8 +176,8 @@ func isClientInList(clientList, client string) bool {
|
||||
if clientList == "" || client == "" {
|
||||
return false
|
||||
}
|
||||
clients := strings.Split(clientList, ",")
|
||||
for _, c := range clients {
|
||||
clients := strings.SplitSeq(clientList, ",")
|
||||
for c := range clients {
|
||||
if strings.TrimSpace(c) == client {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
@@ -120,12 +121,12 @@ func (api *Router) GetLyrics(r *http.Request) (*responses.Subsonic, error) {
|
||||
lyricsResponse.Artist = artist
|
||||
lyricsResponse.Title = title
|
||||
|
||||
lyricsText := ""
|
||||
var lyricsText strings.Builder
|
||||
for _, line := range structuredLyrics[0].Line {
|
||||
lyricsText += line.Value + "\n"
|
||||
lyricsText.WriteString(line.Value + "\n")
|
||||
}
|
||||
|
||||
lyricsResponse.Value = lyricsText
|
||||
lyricsResponse.Value = lyricsText.String()
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ type PlayQueueByIndex struct {
|
||||
}
|
||||
|
||||
type Bookmark struct {
|
||||
Entry Child `xml:"entry,omitempty" json:"entry,omitempty"`
|
||||
Entry Child `xml:"entry,omitempty" json:"entry"`
|
||||
Position int64 `xml:"position,attr,omitempty" json:"position,omitempty"`
|
||||
Username string `xml:"username,attr" json:"username"`
|
||||
Comment string `xml:"comment,attr" json:"comment"`
|
||||
|
||||
@@ -26,17 +26,17 @@ type snapshotMatcher struct {
|
||||
c *cupaloy.Config
|
||||
}
|
||||
|
||||
func (matcher snapshotMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
func (matcher snapshotMatcher) Match(actual any) (success bool, err error) {
|
||||
actualJson := strings.TrimSpace(string(actual.([]byte)))
|
||||
err = matcher.c.SnapshotWithName(ginkgo.CurrentSpecReport().FullText(), actualJson)
|
||||
success = err == nil
|
||||
return
|
||||
}
|
||||
|
||||
func (matcher snapshotMatcher) FailureMessage(_ interface{}) (message string) {
|
||||
func (matcher snapshotMatcher) FailureMessage(_ any) (message string) {
|
||||
return "Expected to match saved snapshot\n"
|
||||
}
|
||||
|
||||
func (matcher snapshotMatcher) NegatedFailureMessage(_ interface{}) (message string) {
|
||||
func (matcher snapshotMatcher) NegatedFailureMessage(_ any) (message string) {
|
||||
return "Expected to not match saved snapshot\n"
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ var _ = Describe("Search", func() {
|
||||
})
|
||||
|
||||
Context("musicFolderId parameter", func() {
|
||||
assertQueryOptions := func(filter squirrel.Sqlizer, expectedQuery string, expectedArgs ...interface{}) {
|
||||
assertQueryOptions := func(filter squirrel.Sqlizer, expectedQuery string, expectedArgs ...any) {
|
||||
GinkgoHelper()
|
||||
query, args, err := filter.ToSql()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Reference in New Issue
Block a user