github.com/camronlevanger/libcompose@v0.4.1-0.20180423130544-6bb86d53fa21/config/utils.go (about)

     1  package config
     2  
     3  func merge(existing, value interface{}) interface{} {
     4  	// append strings
     5  	if left, lok := existing.([]interface{}); lok {
     6  		if right, rok := value.([]interface{}); rok {
     7  			return append(left, right...)
     8  		}
     9  	}
    10  
    11  	//merge maps
    12  	if left, lok := existing.(map[interface{}]interface{}); lok {
    13  		if right, rok := value.(map[interface{}]interface{}); rok {
    14  			newLeft := make(map[interface{}]interface{})
    15  			for k, v := range left {
    16  				newLeft[k] = v
    17  			}
    18  			for k, v := range right {
    19  				newLeft[k] = v
    20  			}
    21  			return newLeft
    22  		}
    23  	}
    24  
    25  	return value
    26  }
    27  
    28  func clone(in RawService) RawService {
    29  	result := RawService{}
    30  	for k, v := range in {
    31  		result[k] = v
    32  	}
    33  
    34  	return result
    35  }
    36  
    37  func asString(obj interface{}) string {
    38  	if v, ok := obj.(string); ok {
    39  		return v
    40  	}
    41  	return ""
    42  }