utils.go 786 B

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