forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
62 lines (48 loc) · 1.41 KB
/
client.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
// Package router is a GoLang library that interacts with CloudFoundry Go Router
package router
import (
"fmt"
"runtime"
"code.cloudfoundry.org/cli/api/router/internal"
"github.com/tedsuo/rata"
)
// Client is a client that can be used to talk to a Cloud Controller's V2
// Endpoints.
type Client struct {
routerGroupEndpoint string
connection Connection
router *rata.RequestGenerator
userAgent string
}
// Config allows the Client to be configured
type Config struct {
// AppName is the name of the application/process using the client.
AppName string
// AppVersion is the version of the application/process using the client.
AppVersion string
// ConnectionConfig is the configuration for the client connection.
ConnectionConfig
// RoutingEndpoint is the url of the router API.
RoutingEndpoint string
// Wrappers that apply to the client connection.
Wrappers []ConnectionWrapper
}
// NewClient returns a new Router Client.
func NewClient(config Config) *Client {
userAgent := fmt.Sprintf("%s/%s (%s; %s %s)",
config.AppName,
config.AppVersion,
runtime.Version(),
runtime.GOARCH,
runtime.GOOS,
)
client := Client{
userAgent: userAgent,
router: rata.NewRequestGenerator(config.RoutingEndpoint, internal.APIRoutes),
connection: NewConnection(config.ConnectionConfig),
}
for _, wrapper := range config.Wrappers {
client.connection = wrapper.Wrap(client.connection)
}
return &client
}