MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / GetVersionByApi

Function GetVersionByApi

cli/internal/apk/server/version.go:31–69  ·  view source on GitHub ↗

获取工作区详情

(auth model.Auth)

Source from the content-addressed store, hash-verified

29
30// 获取工作区详情
31func GetVersionByApi(auth model.Auth) (version string, err error) {
32 if (auth == model.Auth{}) {
33 err = errors.New("用户未登录!")
34 return
35 }
36
37 url := fmt.Sprint(auth.LoginUrl, "/api/system/getVersion")
38 queryparams := map[string]string{}
39
40 httpClient := common.CreateHttpClientEnableRetry()
41 response, err := httpClient.Get(url,
42 queryparams, map[string]string{
43 "Content-Type": "application/json",
44 "x-token": auth.Token.(string),
45 })
46
47 if err != nil {
48 return
49 }
50 if response == "" {
51 return "", errors.New("服务器访问空数据!")
52 }
53
54 var objResponse struct {
55 Code int `json:"code"`
56 Data struct {
57 Version string `json:"version"`
58 } `json:"data"`
59 }
60 err = json.Unmarshal([]byte(response), &objResponse)
61 if err != nil {
62 return "", err
63 }
64
65 if objResponse.Code == 0 {
66 version = objResponse.Data.Version
67 }
68 return version, err
69}

Callers

nothing calls this directly

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected