tests/cldcbdb_client/main.go

60 lines
1.5 KiB
Go

package main
import (
"encoding/json"
"errors"
tnt15 "github.com/lomik/go-tnt"
"gitlab.corp.mail.ru/cloud/workdisk/libs.git/log"
"gitlab.corp.mail.ru/cloud/workdisk/libs.git/tarantool15"
"time"
)
type ProjectInfo struct {
IsPaidTariff *bool `json:"is_paid_tariff"`
Users uint32 `json:"users"`
FreezeAt *uint64 `json:"freeze_at"`
TariffEndTime *uint64 `json:"tariff_end_time"`
PID string `json:"id"`
Space uint64 `json:"space"`
Cost float64 `json:"cost"`
Status string `json:"status"`
}
func main() {
cli := tarantool15.NewPool(
"cloudbilling",
[]string{"localhost:3301"},
&tnt15.Options{
ConnectTimeout: 10 * time.Second,
QueryTimeout: 10 * time.Second,
}, nil, "cloudbiz")
cli.Start()
tuples, err := cli.CallARO("cloud_info", &tnt15.Call{
Name: tnt15.Bytes("cloudbilling.api"),
Tuple: tnt15.Tuple{
tnt15.Bytes("requestID"),
tnt15.Bytes("cloud_info"),
tnt15.Bytes("pid"),
tnt15.Bytes("2"),
},
})
if err != nil {
var tntErr tarantool15.Error
if !errors.As(err, &tntErr) || tntErr.Status != 404 {
log.WithError(err).Fatal("call cloudbilling with jeneric err")
}
}
log.
WithStringField("status", string(tuples[0][0])).
WithStringField("message", string(tuples[0][1])).
Infof("cloud_info response")
var response ProjectInfo
if err = json.Unmarshal(tuples[0][1], &response); err != nil {
log.WithError(err).Error("unmarshall response")
}
log.Infof("func response: %+v", response)
}