-
Notifications
You must be signed in to change notification settings - Fork 129
/
options.go
150 lines (120 loc) · 5.1 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package yomo
import (
"crypto/tls"
"log/slog"
"github.com/quic-go/quic-go"
"github.com/yomorun/yomo/core"
"github.com/yomorun/yomo/core/router"
)
type (
// SourceOption is option for the Source.
SourceOption core.ClientOption
// SfnOption is option for the SFN.
SfnOption core.ClientOption
)
// SourceOption Options.
var (
// WithCredential sets the credential method for the Source.
WithCredential = func(payload string) SourceOption { return SourceOption(core.WithCredential(payload)) }
// WithSourceTLSConfig sets tls config for the Source.
WithSourceTLSConfig = func(tc *tls.Config) SourceOption { return SourceOption(core.WithClientTLSConfig(tc)) }
// WithSourceQuicConfig sets quic config for the Source.
WithSourceQuicConfig = func(qc *quic.Config) SourceOption { return SourceOption(core.WithClientQuicConfig(qc)) }
// WithLogger sets logger for the Source.
WithLogger = func(l *slog.Logger) SourceOption { return SourceOption(core.WithLogger(l)) }
// WithSourceReConnect makes source Connect until success, unless authentication fails.
WithSourceReConnect = func() SourceOption { return SourceOption(core.WithReConnect()) }
)
// Sfn Options.
var (
// WithSfnCredential sets the credential method for the Sfn.
WithSfnCredential = func(payload string) SfnOption { return SfnOption(core.WithCredential(payload)) }
// WithSfnTLSConfig sets tls config for the Sfn.
WithSfnTLSConfig = func(tc *tls.Config) SfnOption { return SfnOption(core.WithClientTLSConfig(tc)) }
// WithSfnQuicConfig sets quic config for the Sfn.
WithSfnQuicConfig = func(qc *quic.Config) SfnOption { return SfnOption(core.WithClientQuicConfig(qc)) }
// WithSfnLogger sets logger for the Sfn.
WithSfnLogger = func(l *slog.Logger) SfnOption { return SfnOption(core.WithLogger(l)) }
// WithSfnReConnect makes sfn Connect until success, unless authentication fails.
WithSfnReConnect = func() SfnOption { return SfnOption(core.WithReConnect()) }
// WithSfnAIFunctionDefinition sets AI function definition for the Sfn.
WithSfnAIFunctionDefinition = func(description string, inputModel any) SfnOption {
return SfnOption(core.WithAIFunctionDefinition(description, inputModel))
}
// WithAIFunctionJsonDefinition sets AI function definition for the Sfn in the form of jsonschema string.
WithAIFunctionJsonDefinition = func(jsonschema string) SfnOption {
return SfnOption(core.WithAIFunctionJsonDefinition(jsonschema))
}
// DisableOtelTrace determines whether to disable otel trace.
DisableOtelTrace = func() SfnOption { return SfnOption(core.DisableOtelTrace()) }
)
// ClientOption is option for the upstream Zipper.
type ClientOption = core.ClientOption
type zipperOptions struct {
serverOption []core.ServerOption
clientOption []ClientOption
}
// ZipperOption is option for the Zipper.
type ZipperOption func(*zipperOptions)
var (
// WithAuth sets the zipper authentication method.
WithAuth = func(name string, args ...string) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithAuth(name, args...))
}
}
// WithZipperTLSConfig sets the TLS configuration for the zipper.
WithZipperTLSConfig = func(tc *tls.Config) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithServerTLSConfig(tc))
}
}
// WithZipperQuicConfig sets the QUIC configuration for the zipper.
WithZipperQuicConfig = func(qc *quic.Config) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithServerQuicConfig(qc))
}
}
// WithZipperLogger sets logger for the zipper.
WithZipperLogger = func(l *slog.Logger) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithServerLogger(l))
}
}
// WithRouter sets router for the zipper.
WithRouter = func(r router.Router) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithRouter(r))
}
}
// WithConnector sets connector for the zipper.
WithConnector = func(c core.Connector) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithConnector(c))
}
}
// WithVersionNegotiateFunc sets the version negotiate function for the zipper
WithVersionNegotiateFunc = func(f core.VersionNegotiateFunc) ZipperOption {
return func(zo *zipperOptions) {
zo.serverOption = append(zo.serverOption, core.WithVersionNegotiateFunc(f))
}
}
// WithUpstreamOption provides upstream zipper options for Zipper.
WithUpstreamOption = func(opts ...ClientOption) ZipperOption {
return func(o *zipperOptions) {
o.clientOption = opts
}
}
// WithZipperConnMiddleware sets conn middleware for the zipper.
WithZipperConnMiddleware = func(mw ...core.ConnMiddleware) ZipperOption {
return func(o *zipperOptions) {
o.serverOption = append(o.serverOption, core.WithConnMiddleware(mw...))
}
}
// WithZipperFrameMiddleware sets frame middleware for the zipper.
WithZipperFrameMiddleware = func(mw ...core.FrameMiddleware) ZipperOption {
return func(o *zipperOptions) {
o.serverOption = append(o.serverOption, core.WithFrameMiddleware(mw...))
}
}
)