From 4af8db34d4e3eb4b278574ff3de7a38adb869e82 Mon Sep 17 00:00:00 2001 From: stgleb Date: Thu, 17 Oct 2019 19:05:01 +0300 Subject: [PATCH] Refactor example Add fields to token type and add create method --- examples/golang/main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/golang/main.go b/examples/golang/main.go index 3577c6ac..6b157ff3 100644 --- a/examples/golang/main.go +++ b/examples/golang/main.go @@ -30,16 +30,26 @@ var ( address = flag.String("address", "127.0.0.1:9100", "Address to server as
:") ) -type OpenStorageSdkToken struct{} +type OpenStorageSdkToken struct { + token string + useTls bool +} + +func NewOpenStorageSdkToken(token string, useTls bool) OpenStorageSdkToken { + return OpenStorageSdkToken{ + token: token, + useTls: useTls, + } +} func (t OpenStorageSdkToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{ - "authorization": "bearer " + *token, + "authorization": "bearer " + t.token, }, nil } func (t OpenStorageSdkToken) RequireTransportSecurity() bool { - return *useTls + return t.useTls } func main() { @@ -59,7 +69,7 @@ func main() { // // To accomplish this, we first need to create an object that satisfies the // interface needed by grpc.WithPerRPCCredentials(..) - contextToken := OpenStorageSdkToken{} + contextToken := NewOpenStorageSdkToken(*token, *useTls) dialOptions := []grpc.DialOption{grpc.WithInsecure()} if *useTls {