You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
2.9 KiB
126 lines
2.9 KiB
package hpds_node |
|
|
|
import ( |
|
"crypto/tls" |
|
"git.hpds.cc/Component/network" |
|
"git.hpds.cc/Component/network/frame" |
|
"git.hpds.cc/Component/network/log" |
|
"github.com/quic-go/quic-go" |
|
) |
|
|
|
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. |
|
func WithObserveDataTags(tags ...frame.Tag) Option { |
|
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 |
|
}
|
|
|