...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package client
17
18 import (
19 "context"
20
21 "github.com/hasura/go-graphql-client"
22 )
23
24 type CtrlClient struct {
25 QueryClient *graphql.Client
26 SubscriptionClient *graphql.SubscriptionClient
27 }
28
29 func NewCtrlClient(url string) *CtrlClient {
30 return &CtrlClient{
31 QueryClient: graphql.NewClient(url, nil),
32 SubscriptionClient: graphql.NewSubscriptionClient(url),
33 }
34 }
35
36 func (c *CtrlClient) ListNamespace(ctx context.Context) ([]string, error) {
37 namespaceQuery := new(struct {
38 Namespace []struct {
39 Ns string
40 }
41 })
42
43 err := c.QueryClient.Query(ctx, namespaceQuery, nil)
44 if err != nil {
45 return nil, err
46 }
47
48 var namespaces []string
49 for _, ns := range namespaceQuery.Namespace {
50 namespaces = append(namespaces, ns.Ns)
51 }
52
53 return namespaces, nil
54 }
55