mirror of
https://github.com/Alexey71/opera-proxy.git
synced 2026-05-14 06:30:59 +00:00
Add new API settings
This commit is contained in:
@@ -12,6 +12,22 @@ const (
|
||||
SE_STATUS_OK int64 = 0
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
Code int64
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
return fmt.Sprintf("API responded with error message: code=%d, msg=%q", e.Code, e.Message)
|
||||
}
|
||||
|
||||
func newAPIError(status SEStatusPair) error {
|
||||
return &APIError{
|
||||
Code: status.Code,
|
||||
Message: status.Message,
|
||||
}
|
||||
}
|
||||
|
||||
type SEStatusPair struct {
|
||||
Code int64
|
||||
Message string
|
||||
@@ -85,6 +101,7 @@ type SEGeoListResponse struct {
|
||||
|
||||
type SEIPEntry struct {
|
||||
Geo SEGeoEntry `json:"geo"`
|
||||
Host string `json:"host,omitempty"`
|
||||
IP string `json:"ip"`
|
||||
Ports []uint16 `json:"ports"`
|
||||
}
|
||||
|
||||
+6
-12
@@ -153,8 +153,7 @@ func (c *SEClient) register(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if regRes.Status.Code != SE_STATUS_OK {
|
||||
return fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
regRes.Status.Code, regRes.Status.Message)
|
||||
return newAPIError(regRes.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -174,8 +173,7 @@ func (c *SEClient) RegisterDevice(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if regRes.Status.Code != SE_STATUS_OK {
|
||||
return fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
regRes.Status.Code, regRes.Status.Message)
|
||||
return newAPIError(regRes.Status)
|
||||
}
|
||||
|
||||
c.AssignedDeviceID = regRes.Data.DeviceID
|
||||
@@ -197,8 +195,7 @@ func (c *SEClient) GeoList(ctx context.Context) ([]SEGeoEntry, error) {
|
||||
}
|
||||
|
||||
if geoListRes.Status.Code != SE_STATUS_OK {
|
||||
return nil, fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
geoListRes.Status.Code, geoListRes.Status.Message)
|
||||
return nil, newAPIError(geoListRes.Status)
|
||||
}
|
||||
|
||||
return geoListRes.Data.Geos, nil
|
||||
@@ -218,8 +215,7 @@ func (c *SEClient) Discover(ctx context.Context, requestedGeo string) ([]SEIPEnt
|
||||
}
|
||||
|
||||
if discoverRes.Status.Code != SE_STATUS_OK {
|
||||
return nil, fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
discoverRes.Status.Code, discoverRes.Status.Message)
|
||||
return nil, newAPIError(discoverRes.Status)
|
||||
}
|
||||
|
||||
return discoverRes.Data.IPs, nil
|
||||
@@ -245,8 +241,7 @@ func (c *SEClient) Login(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if loginRes.Status.Code != SE_STATUS_OK {
|
||||
return fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
loginRes.Status.Code, loginRes.Status.Message)
|
||||
return newAPIError(loginRes.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -264,8 +259,7 @@ func (c *SEClient) DeviceGeneratePassword(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if genRes.Status.Code != SE_STATUS_OK {
|
||||
return fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
genRes.Status.Code, genRes.Status.Message)
|
||||
return newAPIError(genRes.Status)
|
||||
}
|
||||
|
||||
c.DevicePassword = genRes.Data.DevicePassword
|
||||
|
||||
Reference in New Issue
Block a user