Files
de-golang-sdk/core/configuration.go
T

105 lines
2.5 KiB
Go
Raw Normal View History

2026-08-26 17:05:17 +03:00
// Code generated by internal codegen utility; DO NOT EDIT.
package core
import (
"maps"
"net/http"
"runtime/debug"
"strings"
"sync"
)
2026-11-26 17:13:28 +03:00
const sdkModulePath = "repository.basistech.ru/BASIS/de-golang-sdk/v2"
2026-08-26 17:05:17 +03:00
type Configuration struct {
ServerURL string `json:"serverURL,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
HTTPClient *http.Client
2026-09-28 11:14:36 +03:00
2026-08-26 17:05:17 +03:00
// SkipCompatibilityCheck disables the automatic compatibility checks performed during authentication.
//
// It does not affect explicit CheckCompatibility calls.
SkipCompatibilityCheck bool `json:"skipCompatibilityCheck,omitempty"`
defaultHeaderMu sync.RWMutex
defaultHeader map[string]string
}
func NewConfiguration() *Configuration {
return &Configuration{
defaultHeader: make(map[string]string),
UserAgent: "de-golang-sdk/" + SDKVersion(),
}
}
// Clone returns an independent configuration copy. The HTTP client is shared,
// while the default headers use independent storage and synchronization.
func (c *Configuration) Clone() *Configuration {
if c == nil {
return nil
}
c.defaultHeaderMu.RLock()
defer c.defaultHeaderMu.RUnlock()
return &Configuration{
ServerURL: c.ServerURL,
UserAgent: c.UserAgent,
HTTPClient: c.HTTPClient,
SkipCompatibilityCheck: c.SkipCompatibilityCheck,
defaultHeader: maps.Clone(c.defaultHeader),
}
}
// SDKVersion returns the module version embedded in the running program.
func SDKVersion() string {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return "devel"
}
return sdkVersionFromBuildInfo(buildInfo)
}
func sdkVersionFromBuildInfo(buildInfo *debug.BuildInfo) string {
if buildInfo == nil {
return "devel"
}
modules := append([]*debug.Module{&buildInfo.Main}, buildInfo.Deps...)
for _, module := range modules {
if module == nil || module.Path != sdkModulePath {
continue
}
if module.Replace != nil {
module = module.Replace
}
version := strings.TrimPrefix(module.Version, "v")
if version == "" || version == "(devel)" {
return "devel"
}
return version
}
return "devel"
}
func (c *Configuration) AddDefaultHeader(key, value string) {
c.defaultHeaderMu.Lock()
defer c.defaultHeaderMu.Unlock()
if c.defaultHeader == nil {
c.defaultHeader = make(map[string]string)
}
c.defaultHeader[http.CanonicalHeaderKey(key)] = value
}
func (c *Configuration) DefaultHeaders() map[string]string {
c.defaultHeaderMu.RLock()
defer c.defaultHeaderMu.RUnlock()
return maps.Clone(c.defaultHeader)
}