forked from mwitkow/grpc-proxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
77 lines (62 loc) · 2.08 KB
/
options.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright © 2015 Michal Witkowski <michal@improbable.io>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package proxy
import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)
type options struct {
creds credentials.TransportCredentials
logger grpclog.Logger
maxConcurrentStreams uint32
}
// A ProxyOption sets options.
type ProxyOption func(*options)
// UsingLogger returns a ProxyOption that makes use of a logger other than the default `grpclogger`.
func UsingLogger(logger grpclog.Logger) ProxyOption {
return func(o *options) {
o.logger = logger
}
}
// MaxConcurrentStreams returns a ProxyOption that will apply a limit on the number
// of concurrent streams to each ServerTransport.
func MaxConcurrentStreams(n uint32) ProxyOption {
return func(o *options) {
o.maxConcurrentStreams = n
}
}
// Creds returns a ProxyOption that sets credentials for server connections.
func Creds(c credentials.TransportCredentials) ProxyOption {
return func(o *options) {
o.creds = c
}
}
type defaultLogger struct{}
func (g *defaultLogger) Fatal(args ...interface{}) {
grpclog.Fatal(args...)
}
func (g *defaultLogger) Fatalf(format string, args ...interface{}) {
grpclog.Fatalf(format, args...)
}
func (g *defaultLogger) Fatalln(args ...interface{}) {
grpclog.Fatalln(args...)
}
func (g *defaultLogger) Print(args ...interface{}) {
grpclog.Print(args...)
}
func (g *defaultLogger) Printf(format string, args ...interface{}) {
grpclog.Printf(format, args...)
}
func (g *defaultLogger) Println(args ...interface{}) {
grpclog.Println(args...)
}