forked from trpc-group/trpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
135 lines (118 loc) · 3.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License,
// A copy of the Apache 2.0 License is included in this file.
//
//
package servicerouter
import (
"context"
)
// Options defines the call options.
type Options struct {
Ctx context.Context
SourceSetName string
DestinationSetName string
DisableServiceRouter bool
Namespace string
SourceNamespace string
SourceServiceName string
SourceEnvName string
DestinationEnvName string
EnvTransfer string
EnvKey string
SourceMetadata map[string]string
DestinationMetadata map[string]string
}
// Option modifies the Options.
type Option func(*Options)
// WithContext returns an Option which sets request context.
func WithContext(ctx context.Context) Option {
return func(o *Options) {
o.Ctx = ctx
}
}
// WithNamespace returns an Option which sets namespace.
func WithNamespace(namespace string) Option {
return func(opts *Options) {
opts.Namespace = namespace
}
}
// WithDisableServiceRouter returns an Option which disables service router.
func WithDisableServiceRouter() Option {
return func(o *Options) {
o.DisableServiceRouter = true
}
}
// WithSourceNamespace returns an Option which sets caller namespace.
func WithSourceNamespace(namespace string) Option {
return func(o *Options) {
o.SourceNamespace = namespace
}
}
// WithSourceServiceName returns an Option which sets caller service name.
func WithSourceServiceName(serviceName string) Option {
return func(o *Options) {
o.SourceServiceName = serviceName
}
}
// WithSourceEnvName returns an Option which sets caller environment name.
func WithSourceEnvName(envName string) Option {
return func(o *Options) {
o.SourceEnvName = envName
}
}
// WithDestinationEnvName returns an Option which sets callee environment name.
func WithDestinationEnvName(envName string) Option {
return func(o *Options) {
o.DestinationEnvName = envName
}
}
// WithEnvTransfer returns an Option which sets transparent environment information.
func WithEnvTransfer(envTransfer string) Option {
return func(o *Options) {
o.EnvTransfer = envTransfer
}
}
// WithEnvKey returns an Option which sets environment key.
func WithEnvKey(key string) Option {
return func(o *Options) {
o.EnvKey = key
}
}
// WithSourceSetName returns an Option which sets caller set name.
func WithSourceSetName(sourceSetName string) Option {
return func(o *Options) {
o.SourceSetName = sourceSetName
}
}
// WithDestinationSetName returns an Option which sets callee set name.
func WithDestinationSetName(destinationSetName string) Option {
return func(o *Options) {
o.DestinationSetName = destinationSetName
}
}
// WithSourceMetadata returns an Option which sets caller metadata.
func WithSourceMetadata(key string, val string) Option {
return func(o *Options) {
if o.SourceMetadata == nil {
o.SourceMetadata = make(map[string]string)
}
o.SourceMetadata[key] = val
}
}
// WithDestinationMetadata returns an Option which sets callee metadata.
func WithDestinationMetadata(key string, val string) Option {
return func(o *Options) {
if o.DestinationMetadata == nil {
o.DestinationMetadata = make(map[string]string)
}
o.DestinationMetadata[key] = val
}
}