-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosts.go
47 lines (36 loc) · 946 Bytes
/
hosts.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
44
45
46
47
package alldebrid
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
//Domains is the domains response struct
type Domains struct {
Status string `json:"status"`
Data domainsData `json:"data,omitempty"`
Error alldebridError `json:"error,omitempty"`
}
type domainsData struct {
Hosts []string `json:"hosts"`
Streams []string `json:"streams"`
Redirectors []string `json:"redirectors"`
}
//GetDomainsOnly returns list of supported hosts domains and redirectors
func (c *Client) GetDomainsOnly() (Domains, error) {
resp, err := http.Get(fmt.Sprintf(hostsdomains, getHostsEndpoint(), c.ic.appName))
if err != nil {
return Domains{}, err
}
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)
var doms Domains
err = decoder.Decode(&doms)
if err != nil {
return Domains{}, err
}
if doms.Status != "success" {
return Domains{}, errors.New(doms.Error.Message)
}
return doms, nil
}