utils.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package utils
  13. import (
  14. // nolint:gosec
  15. "crypto/md5"
  16. "fmt"
  17. "reflect"
  18. )
  19. // MergeByteMap merges map of byte slices.
  20. func MergeByteMap(dst, src map[string][]byte) map[string][]byte {
  21. for k, v := range src {
  22. dst[k] = v
  23. }
  24. return dst
  25. }
  26. // MergeStringMap performs a deep clone from src to dest.
  27. func MergeStringMap(dest, src map[string]string) {
  28. for k, v := range src {
  29. dest[k] = v
  30. }
  31. }
  32. // IsNil checks if an Interface is nil.
  33. func IsNil(i interface{}) bool {
  34. return i == nil || reflect.ValueOf(i).IsNil()
  35. }
  36. // ObjectHash calculates md5 sum of the data contained in the secret.
  37. // nolint:gosec
  38. func ObjectHash(object interface{}) string {
  39. textualVersion := fmt.Sprintf("%+v", object)
  40. return fmt.Sprintf("%x", md5.Sum([]byte(textualVersion)))
  41. }