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:
ginuerzh
2026-05-25 23:38:35 +08:00
parent 18f39f940b
commit aabebd047b
9 changed files with 992 additions and 5 deletions
+8 -1
View File
@@ -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 &parallelStrategy[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(&parallelTransporter{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 &parallelTransporter{
nodes: append([]*chain.Node(nil), tr.nodes...),