(nodeID string)
| 792 | } |
| 793 | |
| 794 | func (a *API) clientFor(nodeID string) (*nodes.Client, error) { |
| 795 | // 命中缓存直接返回(避免重复构造) |
| 796 | if v, ok := a.clientCache.Load(nodeID); ok { |
| 797 | return v.(*nodes.Client), nil |
| 798 | } |
| 799 | node, err := a.store.Get(nodeID) |
| 800 | if err != nil { |
| 801 | return nil, err |
| 802 | } |
| 803 | if node.Disabled { |
| 804 | return nil, fmt.Errorf("node is disabled") |
| 805 | } |
| 806 | client := a.clientFactory(node) |
| 807 | a.clientCache.Store(nodeID, client) |
| 808 | return client, nil |
| 809 | } |
| 810 | |
| 811 | func (a *API) evictClient(nodeID string) { |
| 812 | a.clientCache.Delete(nodeID) |
no test coverage detected