This commit is contained in:
2023-03-14 14:45:51 +03:00
parent 42800ac4fe
commit f3a1a4c83f
202 changed files with 6199 additions and 155 deletions

View File

@@ -5,7 +5,7 @@ import (
"net/http"
"time"
"github.com/rudecs/decort-sdk/config"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config"
)
func NewHttpClient(cfg config.Config) *http.Client {

View File

@@ -3,9 +3,10 @@ package client
import (
"crypto/tls"
"net/http"
"net/url"
"time"
"github.com/rudecs/decort-sdk/config"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config"
)
// NewLegacyHttpClient creates legacy HTTP Client
@@ -20,8 +21,8 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
return &http.Client{
Transport: &transportLegacy{
base: transCfg,
username: cfg.Username,
password: cfg.Password,
username: url.QueryEscape(cfg.Username),
password: url.QueryEscape(cfg.Password),
retries: cfg.Retries,
token: cfg.Token,
decortURL: cfg.DecortURL,

View File

@@ -41,10 +41,12 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
t.token = token
}
tokenValue := fmt.Sprintf("authkey=%s", t.token)
tokenValue := fmt.Sprintf("&authkey=%s", t.token)
tokenReader := strings.NewReader(tokenValue)
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), tokenReader)
newBody := io.MultiReader(request.Body, tokenReader)
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), newBody)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")

View File

@@ -0,0 +1,18 @@
package serialization
import (
"os"
)
type Writable interface {
WriteToFile(string) error
}
type Serialized []byte
// WriteToFile writes serialized data to specified file.
//
// Make sure to use .json extension for best compatibility.
func (s Serialized) WriteToFile(path string) error {
return os.WriteFile(path, s, 0600)
}