-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
40 lines (31 loc) · 1.1 KB
/
api.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
package kafka
import (
"context"
"fmt"
"net/http"
"github.com/aerogear/charmil-plugin-example/pkg/api/kas"
"github.com/aerogear/charmil-plugin-example/pkg/kafka/kafkaerr"
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
)
func GetKafkaByID(ctx context.Context, api kafkamgmtclient.DefaultApi, id string) (*kafkamgmtclient.KafkaRequest, *http.Response, error) {
r := api.GetKafkaById(ctx, id)
kafkaReq, httpResponse, err := r.Execute()
if kas.IsErr(err, kas.ErrorNotFound) {
return nil, httpResponse, kafkaerr.NotFoundByIDError(id)
}
return &kafkaReq, httpResponse, err
}
func GetKafkaByName(ctx context.Context, api kafkamgmtclient.DefaultApi, name string) (*kafkamgmtclient.KafkaRequest, *http.Response, error) {
r := api.GetKafkas(ctx)
r = r.Search(fmt.Sprintf("name = %v", name))
kafkaList, httpResponse, err := r.Execute()
if err != nil {
return nil, httpResponse, err
}
if kafkaList.GetTotal() == 0 {
return nil, nil, kafkaerr.NotFoundByNameError(name)
}
items := kafkaList.GetItems()
kafkaReq := items[0]
return &kafkaReq, httpResponse, err
}