Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor example #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions examples/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ var (
address = flag.String("address", "127.0.0.1:9100", "Address to server as <address>:<port>")
)

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() {
Expand All @@ -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 {
Expand Down