-
Notifications
You must be signed in to change notification settings - Fork 14
/
downstreambuilder.go
48 lines (38 loc) · 1.37 KB
/
downstreambuilder.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
package core
import (
"net/http"
"time"
"github.com/anz-bank/sysl-go/common"
"google.golang.org/grpc"
"github.com/anz-bank/sysl-go/config"
)
func BuildDownstreamHTTPClient(serviceName string, cfg *config.CommonDownstreamData) (*http.Client, error) {
if cfg == nil {
return buildDefaultHTTPClient(serviceName)
}
client, err := config.DefaultHTTPClient(cfg)
if err != nil {
return nil, err
}
client.Transport = common.NewLoggingRoundTripper(serviceName, client.Transport)
return client, nil
}
func buildDefaultHTTPClient(serviceName string) (*http.Client, error) {
client, err := config.DefaultHTTPClient(nil)
if err != nil {
return nil, err
}
client.Timeout = time.Minute
client.Transport = common.NewLoggingRoundTripper(serviceName, client.Transport)
return client, nil
}
// BuildDownstreamGRPCClient creates a grpc client connection to the target indicated by cfg.ServiceAddress.
// The dial options can be customised by cfg or by hooks, see ResolveGrpcDialOptions for details. The
// serviceName is the name of the target service. This function is intended to be called from generated code.
func BuildDownstreamGRPCClient(serviceName string, hooks *Hooks, cfg *config.CommonGRPCDownstreamData) (*grpc.ClientConn, error) {
opts, err := ResolveGrpcDialOptions(serviceName, hooks, cfg)
if err != nil {
return nil, err
}
return grpc.Dial(cfg.ServiceAddress, opts...)
}