fix(selector): safe type assertion, clean up debug logging, add doc comments and 64 tests
Replace bare type assertion in ParallelStrategy with comma-ok check to prevent panic on non-Node inputs. Downgrade noisy Infof hash-selection log to Tracef and remove Chinese-language debug output. Add doc comments to all exported symbols in weighted.go.
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
|
||||
type parallelStrategy[T any] struct{}
|
||||
|
||||
// ParallelStrategy is a strategy for node selector.
|
||||
// It dials all nodes concurrently and uses the first successful connection.
|
||||
func ParallelStrategy[T any]() selector.Strategy[T] {
|
||||
return ¶llelStrategy[T]{}
|
||||
}
|
||||
@@ -29,7 +31,11 @@ func (s *parallelStrategy[T]) Apply(ctx context.Context, vs ...T) (v T) {
|
||||
|
||||
nodes := make([]*chain.Node, 0, len(vs))
|
||||
for _, node := range vs {
|
||||
nodes = append(nodes, any(node).(*chain.Node))
|
||||
n, ok := any(node).(*chain.Node)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
nodes = append(nodes, n)
|
||||
}
|
||||
|
||||
vn := chain.NewNode("parallel", "", chain.TransportNodeOption(¶llelTransporter{nodes: nodes}))
|
||||
@@ -160,6 +166,7 @@ func (tr *parallelTransporter) Options() *chain.TransportOptions {
|
||||
return &chain.TransportOptions{}
|
||||
}
|
||||
|
||||
// Copy implements chain.Transporter.Copy.
|
||||
func (tr *parallelTransporter) Copy() chain.Transporter {
|
||||
return ¶llelTransporter{
|
||||
nodes: append([]*chain.Node(nil), tr.nodes...),
|
||||
|
||||
Reference in New Issue
Block a user