add protocol option for node

This commit is contained in:
ginuerzh
2022-11-30 10:47:27 +08:00
parent 0f0679a3ec
commit 8effb0b8b9
2 changed files with 16 additions and 2 deletions

View File

@ -3,8 +3,9 @@ package chain
import "context" import "context"
type SelectOptions struct { type SelectOptions struct {
Addr string Addr string
Host string Host string
Protocol string
} }
type SelectOption func(*SelectOptions) type SelectOption func(*SelectOptions)
@ -21,6 +22,12 @@ func HostSelectOption(host string) SelectOption {
} }
} }
func ProtocolSelectOption(protocol string) SelectOption {
return func(o *SelectOptions) {
o.Protocol = protocol
}
}
type Hop interface { type Hop interface {
Nodes() []*Node Nodes() []*Node
Select(ctx context.Context, opts ...SelectOption) *Node Select(ctx context.Context, opts ...SelectOption) *Node

View File

@ -15,6 +15,7 @@ type NodeOptions struct {
HostMapper hosts.HostMapper HostMapper hosts.HostMapper
Metadata metadata.Metadata Metadata metadata.Metadata
Host string Host string
Protocol string
} }
type NodeOption func(*NodeOptions) type NodeOption func(*NodeOptions)
@ -49,6 +50,12 @@ func HostNodeOption(host string) NodeOption {
} }
} }
func ProtocolNodeOption(protocol string) NodeOption {
return func(o *NodeOptions) {
o.Protocol = protocol
}
}
func MetadataNodeOption(md metadata.Metadata) NodeOption { func MetadataNodeOption(md metadata.Metadata) NodeOption {
return func(o *NodeOptions) { return func(o *NodeOptions) {
o.Metadata = md o.Metadata = md