mirror of
https://github.com/Snawoot/windscribe-proxy.git
synced 2026-04-03 11:19:02 +00:00
wndclient: server list done
This commit is contained in:
15
main.go
15
main.go
@@ -2,7 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Snawoot/windscribe-proxy/wndclient"
|
||||
)
|
||||
@@ -27,6 +29,17 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("wndc=%#v\n", wndc)
|
||||
fmt.Printf("Username = %s\nPassword = %s\n", wndc.ProxyUsername, wndc.ProxyPassword)
|
||||
|
||||
list, err := wndc.ServerList(context.TODO())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
err = enc.Encode(list)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ type ServerCredentialsResponse struct {
|
||||
}
|
||||
|
||||
type ServerListResponse struct {
|
||||
Data *ServerList `json:"data"`
|
||||
Data ServerList `json:"data"`
|
||||
Info *struct {
|
||||
Revision int `json:"revision"`
|
||||
RevisionHash string `json:"revision_hash"`
|
||||
|
||||
@@ -203,13 +203,13 @@ func (c *WndClient) ServerCredentials(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WndClient) ServerList(ctx context.Context) error {
|
||||
func (c *WndClient) ServerList(ctx context.Context) (ServerList, error) {
|
||||
c.Mux.Lock()
|
||||
defer c.Mux.Unlock()
|
||||
|
||||
requestUrl, err := url.Parse(c.Settings.Endpoints.ServerList)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
isPremium := "0"
|
||||
if c.IsPremium {
|
||||
@@ -221,13 +221,13 @@ func (c *WndClient) ServerList(ctx context.Context) error {
|
||||
|
||||
err = c.getJSON(ctx, requestUrl.String(), &output)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if output.Data == nil {
|
||||
return ErrNoDataInResponse
|
||||
return nil, ErrNoDataInResponse
|
||||
}
|
||||
|
||||
return nil
|
||||
return output.Data, nil
|
||||
}
|
||||
|
||||
func (c *WndClient) postJSON(ctx context.Context, endpoint string, input, output interface{}) error {
|
||||
|
||||
Reference in New Issue
Block a user