forked from dianhsu-official/cf-tool
/
status.go
40 lines (36 loc) · 811 Bytes
/
status.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
package sio_client
import (
"encoding/json"
"errors"
"github.com/Arapak/sio-tool/util"
)
const ErrorNoActiveRound = "there is no active round in this contest"
type RoundInfo struct {
Time float64 `json:"time"`
RoundStartDate float64 `json:"round_start_date"`
RoundName string `json:"round_name"`
Username string `json:"user"`
}
func (c *SioClient) status(info Info) (roundInfo RoundInfo, err error) {
URL, err := info.StatusURL(c.host)
if err != nil {
return
}
body, err := util.GetBody(c.client, URL)
if err != nil {
return
}
err = json.Unmarshal(body, &roundInfo)
if err != nil {
return
}
if roundInfo.Username == "" {
err = errors.New(ErrorNotLogged)
return
}
if roundInfo.RoundName == "" {
err = errors.New(ErrorNoActiveRound)
return
}
return
}