1.5.8-k8s-extnet-branch v1.4.4
Tim Tkachev 2 years ago
parent 2a1593f45f
commit c9e4ae6afe

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

@ -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)
}
@ -648,6 +656,8 @@ func main() {
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.

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

@ -4,5 +4,6 @@
"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

@ -3,5 +3,6 @@
"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

Loading…
Cancel
Save