refactor: 优化单个和批量哈希查询的响应处理方式
This commit is contained in:
parent
a2d17709ed
commit
5dfc935f18
@ -394,17 +394,14 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response map[string]struct {
|
var response = make(map[string]struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
})
|
||||||
if len(batchHashs) == 1 {
|
if len(batchHashs) == 1 {
|
||||||
var singleResponse struct {
|
var singleResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &singleResponse)
|
err = json.Unmarshal(body, &singleResponse)
|
||||||
response = make(map[string]struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
})
|
|
||||||
response[batchHashs[0]] = singleResponse
|
response[batchHashs[0]] = singleResponse
|
||||||
} else {
|
} else {
|
||||||
err = json.Unmarshal(body, &response)
|
err = json.Unmarshal(body, &response)
|
||||||
|
@ -422,17 +422,14 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response map[string]struct {
|
var response = make(map[string]struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
})
|
||||||
if len(batchHashs) == 1 {
|
if len(batchHashs) == 1 {
|
||||||
var singleResponse struct {
|
var singleResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &singleResponse)
|
err = json.Unmarshal(body, &singleResponse)
|
||||||
response = make(map[string]struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
})
|
|
||||||
response[batchHashs[0]] = singleResponse
|
response[batchHashs[0]] = singleResponse
|
||||||
} else {
|
} else {
|
||||||
err = json.Unmarshal(body, &response)
|
err = json.Unmarshal(body, &response)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user