github.com/whiteboxio/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/cfg/scalar_provider.go (about)

     1  package cfg
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/awesome-flow/flow/pkg/types"
     7  )
     8  
     9  type ScalarConfigProvider struct {
    10  	weight int
    11  	name   string
    12  	kv     *types.KeyValue
    13  }
    14  
    15  var _ Provider = (*ScalarConfigProvider)(nil)
    16  
    17  func NewScalarConfigProvider(kv *types.KeyValue, repo *Repository, weight int) (*ScalarConfigProvider, error) {
    18  	p := &ScalarConfigProvider{
    19  		weight: weight,
    20  		kv:     kv,
    21  		name:   fmt.Sprintf("scalar-provider-%s", kv.Key),
    22  	}
    23  	repo.RegisterKey(kv.Key, p)
    24  
    25  	return p, nil
    26  }
    27  
    28  func (s *ScalarConfigProvider) Name() string {
    29  	return s.name
    30  }
    31  
    32  func (s *ScalarConfigProvider) Depends() []string {
    33  	return []string{}
    34  }
    35  
    36  func (*ScalarConfigProvider) SetUp(repo *Repository) error {
    37  	return nil
    38  }
    39  
    40  func (*ScalarConfigProvider) TearDown(*Repository) error {
    41  	return nil
    42  }
    43  
    44  func (s *ScalarConfigProvider) Get(key types.Key) (*types.KeyValue, bool) {
    45  	if key.Equals(s.kv.Key) {
    46  		return s.kv, true
    47  	}
    48  
    49  	return nil, false
    50  }
    51  
    52  func (s *ScalarConfigProvider) Weight() int {
    53  	return s.weight
    54  }