diff --git a/.golangci.yml b/.golangci.yml index d761778..b248c06 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -101,7 +101,6 @@ linters: disable-all: true enable: - deadcode - - depguard - errcheck - goconst - gofmt # On why gofmt when goimports is enabled - https://github.com/golang/go/issues/21476 diff --git a/cluster.go b/cluster.go index 0113c80..722ca18 100644 --- a/cluster.go +++ b/cluster.go @@ -113,22 +113,22 @@ func (cl *Cluster[T]) Err() error { } // Node returns cluster node with specified status -func (cl *Cluster[T]) Node(criteria NodeStateCriteria) *Node[T] { - return pickNodeByCriteria(cl.checkedNodes.Load().(CheckedNodes[T]), cl.picker, criteria) +func (cl *Cluster[T]) Node(criterion NodeStateCriterion) *Node[T] { + return pickNodeByCriterion(cl.checkedNodes.Load().(CheckedNodes[T]), cl.picker, criterion) } // WaitForNode with specified status to appear or until context is canceled -func (cl *Cluster[T]) WaitForNode(ctx context.Context, criteria NodeStateCriteria) (*Node[T], error) { +func (cl *Cluster[T]) WaitForNode(ctx context.Context, criterion NodeStateCriterion) (*Node[T], error) { // Node already exists? - node := cl.Node(criteria) + node := cl.Node(criterion) if node != nil { return node, nil } - ch := cl.addUpdateSubscriber(criteria) + ch := cl.addUpdateSubscriber(criterion) // Node might have appeared while we were adding waiter, recheck - node = cl.Node(criteria) + node = cl.Node(criterion) if node != nil { return node, nil } @@ -190,11 +190,11 @@ func (cl *Cluster[T]) updateNodes(ctx context.Context) { cl.tracer.NotifiedWaiters() } -// pickNodeByCriteria is a helper function to pick a single node by given criteria -func pickNodeByCriteria[T Querier](nodes CheckedNodes[T], picker NodePicker[T], criteria NodeStateCriteria) *Node[T] { +// pickNodeByCriterion is a helper function to pick a single node by given criterion +func pickNodeByCriterion[T Querier](nodes CheckedNodes[T], picker NodePicker[T], criterion NodeStateCriterion) *Node[T] { var subset []CheckedNode[T] - switch criteria { + switch criterion { case Alive: subset = nodes.alive case Primary: diff --git a/cluster_test.go b/cluster_test.go index 97922ab..085f5fe 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -135,9 +135,9 @@ func TestCluster_Node(t *testing.T) { cl := new(Cluster[*sql.DB]) cl.checkedNodes.Store(CheckedNodes[*sql.DB]{}) - // all criterias must return nil node - for i := Alive; i < maxNodeCriteria; i++ { - node := cl.Node(NodeStateCriteria(i)) + // all criteria must return nil node + for i := Alive; i < maxNodeCriterion; i++ { + node := cl.Node(NodeStateCriterion(i)) assert.Nil(t, node) } }) diff --git a/go.sum b/go.sum index 60d5256..54f288b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= -github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/node.go b/node.go index b68e405..7f45c23 100644 --- a/node.go +++ b/node.go @@ -16,23 +16,23 @@ package hasql -type NodeStateCriteria uint8 +type NodeStateCriterion uint8 const ( - // Alive is a criteria to choose any alive node - Alive NodeStateCriteria = iota + 1 - // Primary is a criteria to choose primary node + // Alive is a criterion to choose any alive node + Alive NodeStateCriterion = iota + 1 + // Primary is a criterion to choose primary node Primary - // Standby is a criteria to choose standby node + // Standby is a criterion to choose standby node Standby - // PreferPrimary is a criteria to choose primary or any alive node + // PreferPrimary is a criterion to choose primary or any alive node PreferPrimary - // PreferStandby is a criteria to choose standby or any alive node + // PreferStandby is a criterion to choose standby or any alive node PreferStandby - // maxNodeCriteria is for testing purposes only - // any new criteria must be added above this constant - maxNodeCriteria + // maxNodeCriterion is for testing purposes only + // all new criteria must be added above this constant + maxNodeCriterion ) type Node[T Querier] struct { diff --git a/notify.go b/notify.go index 31ad18c..d913951 100644 --- a/notify.go +++ b/notify.go @@ -18,18 +18,18 @@ package hasql // updateSubscriber represents a waiter for newly checked node event type updateSubscriber[T Querier] struct { - ch chan *Node[T] - criteria NodeStateCriteria + ch chan *Node[T] + criterion NodeStateCriterion } // addUpdateSubscriber adds new dubscriber to notification pool -func (cl *Cluster[T]) addUpdateSubscriber(criteria NodeStateCriteria) <-chan *Node[T] { +func (cl *Cluster[T]) addUpdateSubscriber(criterion NodeStateCriterion) <-chan *Node[T] { // buffered channel is essential // read WaitForNode function for more information ch := make(chan *Node[T], 1) cl.subscribersMu.Lock() defer cl.subscribersMu.Unlock() - cl.subscribers = append(cl.subscribers, updateSubscriber[T]{ch: ch, criteria: criteria}) + cl.subscribers = append(cl.subscribers, updateSubscriber[T]{ch: ch, criterion: criterion}) return ch } @@ -46,7 +46,7 @@ func (cl *Cluster[T]) notifyUpdateSubscribers(nodes CheckedNodes[T]) { var nodelessWaiters []updateSubscriber[T] // Notify all waiters for _, subscriber := range cl.subscribers { - node := pickNodeByCriteria(nodes, cl.picker, subscriber.criteria) + node := pickNodeByCriterion(nodes, cl.picker, subscriber.criterion) if node == nil { // Put waiter back nodelessWaiters = append(nodelessWaiters, subscriber)