Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9e4ae6afe | |||
| 2a1593f45f |
@@ -1,4 +1,4 @@
|
||||
## Version 1.4.3
|
||||
## Version 1.4.4
|
||||
|
||||
### Bug Fixes
|
||||
- Fixed possible nil-pointer reference to validator instance (in concurrent conditions).
|
||||
### Features
|
||||
- Added "Timeout" param to Config/LegacyConfig that allows configuring HTTP client timeout
|
||||
|
||||
17
README.md
17
README.md
@@ -118,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
@@ -127,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
func main(){
|
||||
// Настройка конфигурации
|
||||
cfg := config.Config{
|
||||
@@ -136,6 +138,8 @@ func main(){
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -165,6 +169,7 @@ func main() {
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
```
|
||||
@@ -177,6 +182,7 @@ appSecret: <APP_SECRET>
|
||||
ssoUrl: https://sso.digitalenergy.online
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
```
|
||||
|
||||
@@ -204,6 +210,8 @@ func main() {
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
}
|
||||
@@ -647,6 +655,8 @@ func main() {
|
||||
DecortURL: "<DECORT_URL>",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
@@ -693,6 +703,7 @@ func main() {
|
||||
| Password | string | Да | пароль legacy пользователя |
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
@@ -711,6 +722,8 @@ func main(){
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
legacyCfg.SetTimeout(5 * time.Minute)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -739,6 +752,7 @@ func main() {
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": true
|
||||
}
|
||||
```
|
||||
@@ -749,6 +763,7 @@ username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: true
|
||||
```
|
||||
### Создание legacy клиента
|
||||
@@ -774,6 +789,8 @@ func main() {
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
legacyCfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
legacyClient := decort.NewLegacy(cfg)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -44,6 +45,15 @@ type Config struct {
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
// HTTP client timeout, unlimited if left empty
|
||||
// Required: false
|
||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
||||
// SetTimeout is used to set HTTP client timeout.
|
||||
func (c *Config) SetTimeout(dur time.Duration) {
|
||||
c.Timeout = Duration(dur)
|
||||
}
|
||||
|
||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -38,6 +39,15 @@ type LegacyConfig struct {
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
// HTTP client timeout, unlimited if left empty
|
||||
// Required: false
|
||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
||||
// SetTimeout is used to set HTTP client timeout.
|
||||
func (c *LegacyConfig) SetTimeout(dur time.Duration) {
|
||||
c.Timeout = Duration(dur)
|
||||
}
|
||||
|
||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
||||
|
||||
50
config/timeouts.go
Normal file
50
config/timeouts.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Duration is a wrapper around time.Duration (used for better user experience)
|
||||
type Duration time.Duration
|
||||
|
||||
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var v interface{}
|
||||
if err := unmarshal(&v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case string:
|
||||
tmp, err := time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||
var v interface{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case string:
|
||||
tmp, err := time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Duration) Get() time.Duration {
|
||||
return time.Duration(*d)
|
||||
}
|
||||
@@ -35,6 +35,6 @@ func NewHttpClient(cfg config.Config) *http.Client {
|
||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
Timeout: 5 * time.Minute,
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
||||
decortURL: cfg.DecortURL,
|
||||
},
|
||||
|
||||
Timeout: 5 * time.Minute,
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ type InfoBackup struct {
|
||||
|
||||
// Backup path
|
||||
BackupPath string `json:"backupPath"`
|
||||
|
||||
// Possible error
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// CreateDisksBackup response
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"sslSkipVerify": false
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
|
||||
ssoUrl: https://sso.digitalenergy.online
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"sslSkipVerify": true
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": true
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: true
|
||||
|
||||
Reference in New Issue
Block a user