Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: common/prpc/options.go

Issue 1637193002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://github.com/luci/luci-go@prpc-server
Patch Set: Add some content length tests. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/prpc/helloworld_test.pb_test.go ('k') | common/prpc/timeout.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package prpc
6
7 import (
8 "fmt"
9 "time"
10
11 "google.golang.org/grpc"
12 "google.golang.org/grpc/metadata"
13
14 "github.com/luci/luci-go/common/retry"
15 )
16
17 // Options controls how RPC requests are sent.
18 type Options struct {
19 Retry retry.Factory // RPC retrial.
20
21 // UserAgent is the value of User-Agent HTTP header.
22 // If empty, DefaultUserAgent is used.
23 UserAgent string
24 Insecure bool // if true, use HTTP instead of HTTPS.
25
26 // the rest can be set only using CallOption.
27
28 resHeaderMetadata *metadata.MD // destination for response HTTP headers .
29 resTrailerMetadata *metadata.MD // destination for response HTTP trailer s.
30 serverDeadline time.Duration
31 }
32
33 // DefaultOptions are used if no options are specified in Client.
34 func DefaultOptions() *Options {
35 return &Options{
36 Retry: func() retry.Iterator {
37 return &retry.ExponentialBackoff{
38 Limited: retry.Limited{
39 Delay: time.Second,
40 Retries: 5,
41 },
42 }
43 },
44 }
45 }
46
47 func (o *Options) apply(callOptions []grpc.CallOption) error {
48 for _, co := range callOptions {
49 prpcCo, ok := co.(CallOption)
50 if !ok {
51 return fmt.Errorf("non-pRPC call option %T is used with pRPC client", co)
52 }
53 prpcCo.apply(o)
54 }
55 return nil
56 }
57
58 // CallOption mutates Options.
59 type CallOption struct {
60 grpc.CallOption
61 // apply mutates options.
62 apply func(*Options)
63 }
64
65 // Header returns a CallOption that retrieves the header metadata.
66 // Can be used instead of with grpc.Header.
67 func Header(md *metadata.MD) *CallOption {
68 return &CallOption{
69 grpc.Header(md),
70 func(o *Options) {
71 o.resHeaderMetadata = md
72 },
73 }
74 }
75
76 // Trailer returns a CallOption that retrieves the trailer metadata.
77 // Can be used instead of grpc.Trailer.
78 func Trailer(md *metadata.MD) *CallOption {
79 return &CallOption{
80 grpc.Trailer(md),
81 func(o *Options) {
82 o.resTrailerMetadata = md
83 },
84 }
85 }
OLDNEW
« no previous file with comments | « common/prpc/helloworld_test.pb_test.go ('k') | common/prpc/timeout.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698