-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
50 lines (41 loc) · 857 Bytes
/
api.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
48
49
50
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
func GetResponse(folder string) (Response, error) {
req, err := http.Get(fmt.Sprintf("https://cloud.mail.ru/api/v2/folder?weblink=%v", folder))
if err != nil {
return Response{}, err
}
defer req.Body.Close()
body, err := io.ReadAll(req.Body)
if err != nil {
return Response{}, err
}
var res Response
err = json.Unmarshal(body, &res)
if err != nil {
return Response{}, err
}
return res, nil
}
func GetWeblink() (string, error) {
req, err := http.Get("https://cloud.mail.ru/api/v2/dispatcher")
if err != nil {
return "", err
}
defer req.Body.Close()
data, err := io.ReadAll(req.Body)
if err != nil {
return "", err
}
var res WeblinkResponse
err = json.Unmarshal(data, &res)
if err != nil {
return "", err
}
return res.Body.WeblinkGet[0].Url, nil
}