-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-vip2-active-monster.go
More file actions
52 lines (43 loc) · 1.18 KB
/
api-vip2-active-monster.go
File metadata and controls
52 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jx3api
import (
"context"
"encoding/json"
"errors"
"log/slog"
)
type MonsterResponse struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Data []struct {
Level int `json:"level"`
Name string `json:"name"`
Skill []string `json:"skill"`
Data struct {
Name string `json:"name"`
List []string `json:"list"`
Desc string `json:"desc"`
} `json:"data"`
} `json:"data"`
}
func (c *Client) ActiveMonster(ctx context.Context) (*MonsterResponse, error) {
raw, err := c.request(ctx, "/data/active/monster", nil)
if err != nil {
slog.Error("ActiveMonster: request error: " + err.Error())
return nil, err
}
resp := new(Response)
if err := json.Unmarshal(raw, &resp); err != nil {
slog.Info("ActiveMonster: response body unmarshal error: " + err.Error())
return nil, err
}
data := new(MonsterResponse)
if resp.Msg != "success" {
slog.Error("ActiveMonster: API error: " + resp.Msg)
return nil, errors.New(resp.Msg)
}
if err := json.Unmarshal(*resp.Data, &data); err != nil {
slog.Info("ActiveMonster: data unmarshal error: " + err.Error())
return nil, err
}
return data, nil
}