github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/util/specobj/defaults.go (about)

     1  package specobj
     2  
     3  import (
     4  	magic "github.com/metux/go-magicdict"
     5  )
     6  
     7  func (so SpecObj) DefaultPutStr(k Key, v string) error {
     8  	return magic.DefaultPutStr(so.Spec, k, v)
     9  }
    10  
    11  func (so SpecObj) DefaultStr(k Key) string {
    12  	return magic.DefaultStr(so.Spec, k)
    13  }
    14  
    15  // Note: this function needs key+value pairs, thus parameter count *must* be even
    16  // passing an odd number of parameters will cause panic
    17  func (so SpecObj) DefaultPutStrs(strs ...string) {
    18  	l := len(strs) / 2
    19  
    20  	for x := 0; x < l; x++ {
    21  		so.DefaultPutStr(Key(strs[x*2]), strs[x*2+1])
    22  	}
    23  }
    24  
    25  func (so SpecObj) DefaultPutStrMap(m map[Key]string) {
    26  	for k, v := range m {
    27  		so.DefaultPutStr(k, v)
    28  	}
    29  }
    30  
    31  func (so SpecObj) DefaultPutStrList(k Key, s []string) error {
    32  	return magic.DefaultPutStrList(so.Spec, k, s)
    33  }