...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/deepcopy/deepcopy.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/deepcopy

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package deepcopy
    16  
    17  func StringStringMap(src map[string]string) map[string]string {
    18  	if src == nil {
    19  		return nil
    20  	}
    21  	dst := make(map[string]string, len(src))
    22  	for k, v := range src {
    23  		dst[k] = v
    24  	}
    25  	return dst
    26  }
    27  
    28  // DeepCopy deeply copies map[string]interface{}, []interface{}, and primitives types.
    29  func DeepCopy(o interface{}) interface{} {
    30  	if m, ok := o.(map[string]interface{}); ok {
    31  		new := make(map[string]interface{})
    32  		for k, v := range m {
    33  			new[k] = DeepCopy(v)
    34  		}
    35  		return new
    36  	}
    37  	if s, ok := o.([]interface{}); ok {
    38  		new := make([]interface{}, 0)
    39  		for _, v := range s {
    40  			new = append(new, DeepCopy(v))
    41  		}
    42  		return new
    43  	}
    44  	return o
    45  }
    46  
    47  func MapStringInterface(o map[string]interface{}) map[string]interface{} {
    48  	return DeepCopy(o).(map[string]interface{})
    49  }
    50  
    51  func StringSlice(src []string) []string {
    52  	dst := make([]string, len(src))
    53  	for i, v := range src {
    54  		dst[i] = v
    55  	}
    56  	return dst
    57  }
    58  

View as plain text