github.com/databricks/cli@v0.203.0/bundle/config/interpolation/setter.go (about)

     1  package interpolation
     2  
     3  import "reflect"
     4  
     5  // String values in maps are not addressable and therefore not settable
     6  // through Go's reflection mechanism. This interface solves this limitation
     7  // by wrapping the setter differently for addressable values and map values.
     8  type setter interface {
     9  	Set(string)
    10  }
    11  
    12  type nilSetter struct{}
    13  
    14  func (nilSetter) Set(_ string) {
    15  	panic("nil setter")
    16  }
    17  
    18  type anySetter struct {
    19  	rv reflect.Value
    20  }
    21  
    22  func (s anySetter) Set(str string) {
    23  	s.rv.SetString(str)
    24  }
    25  
    26  type mapSetter struct {
    27  	// map[string]string
    28  	m reflect.Value
    29  
    30  	// key
    31  	k reflect.Value
    32  }
    33  
    34  func (s mapSetter) Set(str string) {
    35  	s.m.SetMapIndex(s.k, reflect.ValueOf(str))
    36  }
    37  
    38  type getter interface {
    39  	Get() string
    40  }
    41  
    42  type anyGetter struct {
    43  	rv reflect.Value
    44  }
    45  
    46  func (g anyGetter) Get() string {
    47  	return g.rv.String()
    48  }