Update api.go

This commit is contained in:
Akkariin Meiko 2019-09-08 18:32:21 +08:00 committed by GitHub
parent 3df9338222
commit 6a34c73071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,7 +148,38 @@ func (s Service) CheckProxy(user string, pMsg *msg.NewProxy, timestamp int64, st
// GetProxyLimit 获取隧道限速信息
func (s Service) GetProxyLimit(pxyConf *config.BaseProxyConf) (inLimit, outLimit uint64, err error) {
return 1 * limit.MB, 1 * limit.MB, nil
// 这部分就照之前的搬过去了能跑就行x
values := url.Values{}
values.Set("do", "getlimit")
values.Set("user", user)
values.Set("frpstoken", stk)
s.Host.RawQuery = values.Encode()
defer func(u *url.URL) {
u.RawQuery = ""
}(&s.Host)
resp, err := http.Get(s.Host.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
er := &ErrHTTPStatus{}
if err = json.Unmarshal(body, er); err != nil {
return nil, err
}
if er.Status != 200 {
return nil, er
}
r = &ResponseGetLimit{}
if err = json.Unmarshal(body, r); err != nil {
return nil, err
}
return r.MaxIn, r.MaxOut, nil
}
func BoolToString(val bool) (str string) {
@ -168,6 +199,11 @@ func (e ErrHTTPStatus) Error() string {
return fmt.Sprintf("%s", e.Text)
}
type ResponseGetLimit struct {
MaxIn uint64 `json:"max-in"`
MaxOut uint64 `json:"max-out"`
}
type ResponseCheckToken struct {
Success bool `json:"success"`
Message string `json:"message"`