You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/check.go

89 lines
2.2 KiB

package decortsdk
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
)
type CheckInfo struct {
Version string `json:"version"`
Build uint64 `json:"build"`
}
const versionURL = "/system/info/version"
func (de DecortClient) Check() (*CheckInfo, error) {
res, err := de.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
if err != nil {
return nil, err
}
info := CheckInfo{}
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
}
if v, ok := constants.VersionMap[info.Version]; ok {
if v == "-" {
return &info, nil
}
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
}
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
}
func (bvs BVSDecortClient) Check() (*CheckInfo, error) {
res, err := bvs.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
if err != nil {
return nil, err
}
info := CheckInfo{}
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
}
if v, ok := constants.VersionMap[info.Version]; ok {
if v == "-" {
return &info, nil
}
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
}
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
}
func (ldc LegacyDecortClient) Check() (*CheckInfo, error) {
res, err := ldc.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
if err != nil {
return nil, err
}
info := CheckInfo{}
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
}
if v, ok := constants.VersionMap[info.Version]; ok {
if v == "-" {
return &info, nil
}
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
}
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
}