Added webapp Dashboard + logic to interact with server.
[src/xds/xds-agent.git] / lib / agent / apiv1-version.go
1 package agent
2
3 import (
4         "net/http"
5
6         "github.com/gin-gonic/gin"
7         common "github.com/iotbzh/xds-common/golib"
8 )
9
10 type version struct {
11         ID            string `json:"id"`
12         Version       string `json:"version"`
13         APIVersion    string `json:"apiVersion"`
14         VersionGitTag string `json:"gitTag"`
15 }
16
17 type apiVersion struct {
18         Client version   `json:"client"`
19         Server []version `json:"servers"`
20 }
21
22 // getInfo : return various information about server
23 func (s *APIService) getVersion(c *gin.Context) {
24         response := apiVersion{
25                 Client: version{
26                         ID:            "",
27                         Version:       s.Config.Version,
28                         APIVersion:    s.Config.APIVersion,
29                         VersionGitTag: s.Config.VersionGitTag,
30                 },
31         }
32
33         svrVer := []version{}
34         for _, svr := range s.xdsServers {
35                 res := version{}
36                 if err := svr.HTTPGet("/version", &res); err != nil {
37                         common.APIError(c, "Cannot retrieve version of XDS server ID %s : %v", svr.ID, err.Error())
38                         return
39                 }
40                 svrVer = append(svrVer, res)
41         }
42         response.Server = svrVer
43
44         c.JSON(http.StatusOK, response)
45 }