-
Notifications
You must be signed in to change notification settings - Fork 47
/
PriceInfoRest.go
77 lines (61 loc) · 2.04 KB
/
PriceInfoRest.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Cloud Control Manager's Rest Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2023.09.
package restruntime
import (
"encoding/json"
"net/http"
cmrt "github.com/cloud-barista/cb-spider/api-runtime/common-runtime"
cres "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
"github.com/labstack/echo/v4"
)
// ================ PriceInfo Handler
func ListProductFamily(c echo.Context) error {
cblog.Info("call ListProductFamily()")
var req struct {
ConnectionName string
}
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
// To support for Get-Query Param Type API
if req.ConnectionName == "" {
req.ConnectionName = c.QueryParam("ConnectionName")
}
// Call common-runtime API
result, err := cmrt.ListProductFamily(req.ConnectionName, c.Param("RegionName"))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
var jsonResult struct {
Result []string `json:"productfamily"`
}
jsonResult.Result = result
return c.JSON(http.StatusOK, &jsonResult)
}
func GetPriceInfo(c echo.Context) error {
cblog.Info("call GetPriceInfo()")
var req struct {
ConnectionName string
FilterList []cres.KeyValue
}
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
// To support for Get-Query Param Type API
if req.ConnectionName == "" {
req.ConnectionName = c.QueryParam("ConnectionName")
}
// Call common-runtime API
result, err := cmrt.GetPriceInfo(req.ConnectionName, c.Param("ProductFamily"), c.Param("RegionName"), req.FilterList)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
var Result cres.CloudPriceData
json.Unmarshal([]byte(result), &Result)
return c.JSON(http.StatusOK, Result)
}