/
check_db_ver.go
43 lines (36 loc) · 920 Bytes
/
check_db_ver.go
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
package yugioh
import (
"fmt"
"net/http"
)
// CheckDBVersionService ...
type CheckDBVersionService struct {
client *Client
}
// DBInformation ...
type DBInformation struct {
Version string `json:"database_version"`
LastUpdated string `json:"last_update" validate:"datetime"`
}
// One ...
func (s *CheckDBVersionService) One() (DBInformation, *http.Response, error) {
u := defaultBaseURL + "checkDBVer.php"
req, err := s.client.NewRequest(http.MethodGet, u, nil)
if err != nil {
return DBInformation{}, nil, err
}
dbInformation := make([]DBInformation, 1)
resp, err := s.client.Do(req, &dbInformation)
if err != nil {
return DBInformation{}, resp, err
}
if len(dbInformation) == 0 {
err = fmt.Errorf("data does not exist")
return DBInformation{}, resp, err
}
err = Validate(dbInformation[0])
if err != nil {
return DBInformation{}, resp, err
}
return dbInformation[0], resp, err
}