refactor: 优化单个和批量哈希查询的响应处理方式

This commit is contained in:
lixiangwuxian 2025-03-08 21:22:45 +08:00
parent a2d17709ed
commit 5dfc935f18
2 changed files with 4 additions and 10 deletions

View File

@ -394,17 +394,14 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
if err != nil {
return nil, err
}
var response map[string]struct {
var response = make(map[string]struct {
ID string `json:"id"`
}
})
if len(batchHashs) == 1 {
var singleResponse struct {
ID string `json:"id"`
}
err = json.Unmarshal(body, &singleResponse)
response = make(map[string]struct {
ID string `json:"id"`
})
response[batchHashs[0]] = singleResponse
} else {
err = json.Unmarshal(body, &response)

View File

@ -422,17 +422,14 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
if err != nil {
return nil, err
}
var response map[string]struct {
var response = make(map[string]struct {
ID string `json:"id"`
}
})
if len(batchHashs) == 1 {
var singleResponse struct {
ID string `json:"id"`
}
err = json.Unmarshal(body, &singleResponse)
response = make(map[string]struct {
ID string `json:"id"`
})
response[batchHashs[0]] = singleResponse
} else {
err = json.Unmarshal(body, &response)