github.com/searKing/golang/go@v1.2.117/container/hashring/ketamanodelocator_options.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated by "go-option -type NodeLocator"; DO NOT EDIT.
     6  
     7  package hashring
     8  
     9  var _default_KetamaNodeLocator_value = func() (val NodeLocator) { return }()
    10  
    11  // A NodeLocatorOption sets options.
    12  type NodeLocatorOption interface {
    13  	apply(*NodeLocator)
    14  }
    15  
    16  // EmptyKetamaNodeLocatorOption does not alter the configuration. It can be embedded
    17  // in another structure to build custom options.
    18  //
    19  // This API is EXPERIMENTAL.
    20  type EmptyKetamaNodeLocatorOption struct{}
    21  
    22  func (EmptyKetamaNodeLocatorOption) apply(*NodeLocator) {}
    23  
    24  // KetamaNodeLocatorOptionFunc wraps a function that modifies NodeLocator into an
    25  // implementation of the NodeLocatorOption interface.
    26  type KetamaNodeLocatorOptionFunc func(*NodeLocator)
    27  
    28  func (f KetamaNodeLocatorOptionFunc) apply(do *NodeLocator) {
    29  	f(do)
    30  }
    31  
    32  // sample code for option, default for nothing to change
    33  func _KetamaNodeLocatorOptionWithDefault() NodeLocatorOption {
    34  	return KetamaNodeLocatorOptionFunc(func(*NodeLocator) {
    35  		// nothing to change
    36  	})
    37  }
    38  
    39  func (c *NodeLocator) ApplyOptions(options ...NodeLocatorOption) *NodeLocator {
    40  	for _, opt := range options {
    41  		if opt == nil {
    42  			continue
    43  		}
    44  		opt.apply(c)
    45  	}
    46  	return c
    47  }