wndclient: server list done

This commit is contained in:
Vladislav Yarmak
2021-06-24 02:07:19 +03:00
parent a12391751a
commit 91bebb0bf1
3 changed files with 20 additions and 7 deletions

15
main.go
View File

@@ -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)
}
}

View File

@@ -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"`

View File

@@ -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 {