generic: struct for response common fields
This is common across all responses. Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
parent
033357459f
commit
ab40d570eb
@ -1,11 +1,7 @@
|
|||||||
package monstersirenfetch
|
package monstersirenfetch
|
||||||
|
|
||||||
// Albums is the response of /api/albums.
|
// Albums is the response of /api/albums.
|
||||||
type Albums struct {
|
type Albums Response[[]Album]
|
||||||
Code int `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data []Album `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Album represents the metadata of an album.
|
// Album represents the metadata of an album.
|
||||||
type Album struct {
|
type Album struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
var albumsJSON []byte
|
var albumsJSON []byte
|
||||||
|
|
||||||
func TestAlbums(t *testing.T) {
|
func TestAlbums(t *testing.T) {
|
||||||
checkJSONRoundTrip(t, Albums{Code: 0, Msg: "", Data: []Album{
|
checkJSONRoundTrip(t, Albums{Data: []Album{
|
||||||
{CID: 2444, Name: "无忧梦呓OST", CoverURL: "https://web.hycdn.cn/siren/pic/20250905/2039eb5cf7f7d3a951d5f653c6d33f64.jpg", Artists: []string{"塞壬唱片-MSR"}},
|
{CID: 2444, Name: "无忧梦呓OST", CoverURL: "https://web.hycdn.cn/siren/pic/20250905/2039eb5cf7f7d3a951d5f653c6d33f64.jpg", Artists: []string{"塞壬唱片-MSR"}},
|
||||||
{CID: 5192, Name: "焰烬曙明OST", CoverURL: "https://web.hycdn.cn/siren/pic/20250905/6e32685dcc113791d9e90c14e18634c6.jpg", Artists: []string{"塞壬唱片-MSR"}},
|
{CID: 5192, Name: "焰烬曙明OST", CoverURL: "https://web.hycdn.cn/siren/pic/20250905/6e32685dcc113791d9e90c14e18634c6.jpg", Artists: []string{"塞壬唱片-MSR"}},
|
||||||
{CID: 1019, Name: "in your blue eyes", CoverURL: "https://web.hycdn.cn/siren/pic/20250903/63d83dcec8698fde96edcd039d9f4fcf.jpg", Artists: []string{"Ave Mujica"}},
|
{CID: 1019, Name: "in your blue eyes", CoverURL: "https://web.hycdn.cn/siren/pic/20250903/63d83dcec8698fde96edcd039d9f4fcf.jpg", Artists: []string{"Ave Mujica"}},
|
||||||
|
@ -6,6 +6,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Response is a generic API response.
|
||||||
|
type Response[T any] struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data T `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
// StringInt is a JSON string representing an integer.
|
// StringInt is a JSON string representing an integer.
|
||||||
type StringInt int
|
type StringInt int
|
||||||
|
|
||||||
|
6
songs.go
6
songs.go
@ -1,11 +1,7 @@
|
|||||||
package monstersirenfetch
|
package monstersirenfetch
|
||||||
|
|
||||||
// Songs is the response of /api/songs.
|
// Songs is the response of /api/songs.
|
||||||
type Songs struct {
|
type Songs Response[SongData]
|
||||||
Code int `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data SongData `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SongData represents [Songs.Data].
|
// SongData represents [Songs.Data].
|
||||||
type SongData = struct {
|
type SongData = struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
var songsJSON []byte
|
var songsJSON []byte
|
||||||
|
|
||||||
func TestSongs(t *testing.T) {
|
func TestSongs(t *testing.T) {
|
||||||
checkJSONRoundTrip(t, Songs{Code: 0, Msg: "", Data: SongData{List: []Song{
|
checkJSONRoundTrip(t, Songs{Data: SongData{List: []Song{
|
||||||
{CID: 125042, Name: "Sanctuary Inside", AlbumCID: 5194, Artists: []string{"塞壬唱片-MSR"}},
|
{CID: 125042, Name: "Sanctuary Inside", AlbumCID: 5194, Artists: []string{"塞壬唱片-MSR"}},
|
||||||
{CID: 880304, Name: "美梦必须成真", AlbumCID: 2444, Artists: []string{"塞壬唱片-MSR"}},
|
{CID: 880304, Name: "美梦必须成真", AlbumCID: 2444, Artists: []string{"塞壬唱片-MSR"}},
|
||||||
{CID: 779469, Name: "玩乐时间", AlbumCID: 2444, Artists: []string{"塞壬唱片-MSR"}},
|
{CID: 779469, Name: "玩乐时间", AlbumCID: 2444, Artists: []string{"塞壬唱片-MSR"}},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user