summaryrefslogtreecommitdiffstats
path: root/lib/agent/apiv1-version.go
blob: c75e7f5da68714590f8928ed54fcd7bcc7070b8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package agent

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/iotbzh/xds-agent/lib/apiv1"
	common "github.com/iotbzh/xds-common/golib"
)

// getInfo : return various information about server
func (s *APIService) getVersion(c *gin.Context) {
	response := apiv1.XDSVersion{
		Client: apiv1.VersionData{
			ID:            "",
			Version:       s.Config.Version,
			APIVersion:    s.Config.APIVersion,
			VersionGitTag: s.Config.VersionGitTag,
		},
	}

	svrVer := []apiv1.VersionData{}
	for _, svr := range s.xdsServers {
		res := apiv1.VersionData{}
		if err := svr.GetVersion(&res); err != nil {
			common.APIError(c, "Cannot retrieve version of XDS server ID %s : %v", svr.ID, err.Error())
			return
		}
		svrVer = append(svrVer, res)
	}
	response.Server = svrVer

	c.JSON(http.StatusOK, response)
}