forked from orvice/v2ray-mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
36 lines (31 loc) · 897 Bytes
/
http.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
package main
import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"github.com/catpie/musdk-go"
)
func (u *UserManager) httpReq(uri string, method string, buffer string) (string, int, error) {
client := &http.Client{}
req, err := http.NewRequest(method, uri, strings.NewReader(buffer))
if err != nil {
return "", 0, err
}
req.Header.Set("Token", cfg.WebApi.Token)
req.Header.Set("ServiceType", strconv.Itoa(musdk.TypeV2ray))
req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
return "", 0, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
return string(body), res.StatusCode, err
}
func (u *UserManager) httpGet(uri string) (string, int, error) {
return u.httpReq(uri, http.MethodGet, "")
}
func (u *UserManager) httpPost(uri, data string) (string, int, error) {
return u.httpReq(uri, http.MethodPost, data)
}