2022-10-12 11:55:36 +08:00
|
|
|
package hpds_node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"git.hpds.cc/Component/network"
|
2023-04-05 17:25:22 +08:00
|
|
|
"git.hpds.cc/Component/network/frame"
|
2022-10-12 11:55:36 +08:00
|
|
|
"git.hpds.cc/Component/network/log"
|
2023-04-05 17:25:22 +08:00
|
|
|
"github.com/quic-go/quic-go"
|
2022-10-12 11:55:36 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DefaultMqAddr is the default address of downstream mq.
|
|
|
|
DefaultMqAddr = "localhost:9000"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Option is a function that applies a hpds-Client option.
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// Options are the options for YoMo
|
|
|
|
type Options struct {
|
|
|
|
MqAddr string // target mq endpoint address
|
|
|
|
// MqListenAddr string // mq endpoint address
|
|
|
|
MqWorkflowConfig string // mq workflow file
|
|
|
|
MeshConfigURL string // meshConfigURL is the URL of edge-mesh config
|
|
|
|
ServerOptions []network.ServerOption
|
|
|
|
ClientOptions []network.ClientOption
|
|
|
|
QuicConfig *quic.Config
|
|
|
|
TLSConfig *tls.Config
|
|
|
|
Logger log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithMqAddr return a new options with MqAddr set to addr.
|
|
|
|
func WithMqAddr(addr string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.MqAddr = addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// // WithMqListenAddr return a new options with MqListenAddr set to addr.
|
|
|
|
// func WithMqListenAddr(addr string) Option {
|
|
|
|
// return func(o *options) {
|
|
|
|
// o.MqListenAddr = addr
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: WithWorkflowConfig
|
|
|
|
|
|
|
|
// WithMeshConfigURL sets the initial edge-mesh config URL for the YoMo-MessageQueue.
|
|
|
|
func WithMeshConfigURL(url string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.MeshConfigURL = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithTLSConfig sets the TLS configuration for the client.
|
|
|
|
func WithTLSConfig(tc *tls.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.TLSConfig = tc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithQuicConfig sets the QUIC configuration for the client.
|
|
|
|
func WithQuicConfig(qc *quic.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.QuicConfig = qc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithClientOptions returns a new options with opts.
|
|
|
|
func WithClientOptions(opts ...network.ClientOption) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ClientOptions = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithServerOptions returns a new options with opts.
|
|
|
|
func WithServerOptions(opts ...network.ServerOption) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ServerOptions = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAuth sets the server authentication method (used by server)
|
|
|
|
func WithAuth(name string, args ...string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ServerOptions = append(
|
|
|
|
o.ServerOptions,
|
|
|
|
network.WithAuth(name, args...),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCredential sets the client credential method (used by client)
|
|
|
|
func WithCredential(payload string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ClientOptions = append(
|
|
|
|
o.ClientOptions,
|
|
|
|
network.WithCredential(payload),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithObserveDataTags sets client data tag list.
|
2023-04-05 17:25:22 +08:00
|
|
|
func WithObserveDataTags(tags ...frame.Tag) Option {
|
2022-10-12 11:55:36 +08:00
|
|
|
return func(o *Options) {
|
|
|
|
o.ClientOptions = append(
|
|
|
|
o.ClientOptions,
|
|
|
|
network.WithObserveDataTags(tags...),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewOptions creates a new options for YoMo-Client.
|
|
|
|
func NewOptions(opts ...Option) *Options {
|
|
|
|
options := &Options{}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(options)
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.MqAddr == "" {
|
|
|
|
options.MqAddr = DefaultMqAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|