Documentation ¶
Overview ¶
utilities.go For utility/helper functions to support the jamf pro tf provider
utilities.go For utility/helper functions to support the jamf pro tf provider
utilities.go For utility/helper functions to support the jamf pro tf provider
Index ¶
- func Base64EncodeIfNot(value string) string
- func BytesToString(b []byte) string
- func ConvertMap[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, convertKey func(K1) K2, convertValue func(V1) V2) map[K2]V2
- func ConvertSlice[T any, U any](s []T, convert func(T) U) []U
- func ConvertToStringInterface(slice []string) []interface{}
- func DecodePlistToCustomType(data []byte, customType *plistCustomType) (int, error)
- func DecodePlistToMap(data []byte) (map[string]interface{}, int, error)
- func DecodeXmlString(s string) string
- func EncodeCustomTypeToPlist(customType plistCustomType, format int) error
- func EncodeMapToPlist(data map[string]interface{}, format int) error
- func EncodeXmlString(s string) string
- func ExtractSetToStringSlice(set *schema.Set) []string
- func Float64ToInt(f float64) int
- func GetStringValueFromMap(m map[string]interface{}, key string) (string, bool)
- func IntToFloat64(i int) float64
- func IntToString(i int) string
- func JSONToStruct(data string, v interface{}) error
- func MapInterfaceToString(m map[string]interface{}) map[string]string
- func MapStringToInterface(m map[string]string) map[string]interface{}
- func NormalizeXml(xmlString interface{}) string
- func SliceFloat64ToInt(slice []float64) []int
- func SliceIntToFloat64(slice []int) []float64
- func SliceMapInterfaceToString(slice []map[string]interface{}) []map[string]string
- func SliceMapStringToInterface(slice []map[string]string) []map[string]interface{}
- func StringToBytes(s string) []byte
- func StringToInt(s string) (int, error)
- func StructToJSON(v interface{}) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64EncodeIfNot ¶ added in v0.0.11
Base64EncodeIfNot encodes a string value if it isn't already encoded using base64.StdEncoding.EncodeToString. If the input is already base64 encoded, return the original input unchanged.
func BytesToString ¶ added in v0.0.13
BytesToString converts a byte slice to a string.
func ConvertMap ¶ added in v0.0.13
func ConvertMap[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, convertKey func(K1) K2, convertValue func(V1) V2) map[K2]V2
ConvertMap converts a map from one key-value pair type to another. It requires conversion functions for keys and values respectively.
func ConvertSlice ¶ added in v0.0.13
ConvertSlice converts a slice of one type to a slice of another type. It requires a conversion function that defines how individual elements are converted.
func ConvertToStringInterface ¶ added in v0.0.13
func ConvertToStringInterface(slice []string) []interface{}
Helper function to convert slice of strings to slice of empty interfaces
func DecodePlistToCustomType ¶ added in v0.0.11
DecodePlistToCustomType decodes plist data from a byte slice into a provided plistCustomType pointer. Updates the value pointed by `customType` with the decoded data. Returns the format of the plist and an error if decoding fails.
func DecodePlistToMap ¶ added in v0.0.11
DecodePlistToMap decodes plist data from a byte slice into a map[string]interface{}. Returns the decoded map, the format of the plist, and an error if decoding fails.
func DecodeXmlString ¶ added in v0.0.11
DecodeXmlString unescapes HTML entities in a string back to their original XML special characters.
func EncodeCustomTypeToPlist ¶ added in v0.0.11
EncodeCustomTypeToPlist encodes an instance of plistCustomType to a plist format and writes it to standard output. The `format` parameter determines the plist format (e.g., XML, Binary). Returns an error if encoding fails.
func EncodeMapToPlist ¶ added in v0.0.11
EncodeMapToPlist encodes a map[string]interface{} to a plist format and writes it to standard output. The `format` parameter determines the plist format (e.g., XML, Binary). Returns an error if encoding fails.
func EncodeXmlString ¶ added in v0.0.11
EncodeXmlString escapes special XML characters in a string and replaces them with their corresponding HTML entities.
func ExtractSetToStringSlice ¶ added in v0.0.13
Helper function to extract string slice from *schema.Set
func Float64ToInt ¶ added in v0.0.13
Float64ToInt converts a float64 to an int, truncating the decimal part.
func GetStringValueFromMap ¶ added in v0.0.13
GetStringValueFromMap tries to retrieve a string value from a map using the provided key. Returns the value and a boolean indicating whether the operation was successful.
func IntToFloat64 ¶ added in v0.0.13
IntToFloat64 converts an int to a float64.
func IntToString ¶ added in v0.0.13
IntToString converts an int to a string.
func JSONToStruct ¶ added in v0.0.13
JSONToStruct converts a JSON string to a struct. The struct type must be provided by the caller. Returns an error if the conversion is not possible.
func MapInterfaceToString ¶ added in v0.0.13
MapInterfaceToString converts a map with interface{} values to a map with string values. Non-string values will be converted to strings using fmt.Sprint.
func MapStringToInterface ¶ added in v0.0.13
MapStringToInterface converts a map with string values to a map with interface{} values.
func NormalizeXml ¶ added in v0.0.11
func NormalizeXml(xmlString interface{}) string
NormalizeXml takes an XML content represented by the `xmlString` parameter of type `interface{}` and returns a normalized, consistently formatted XML string. The function performs the following steps: 1. Checks if the input `xmlString` is nil or an empty string, returning an empty string if true. 2. Attempts to unmarshal the input string (asserted to `string` from `interface{}`) into a generic interface{} type to parse the XML structure. 3. If unmarshaling fails (indicating invalid XML content), returns an error message string. 4. If unmarshaling succeeds, marshals the object back into XML using `xml.MarshalIndent` to ensure consistent formatting and indentation. 5. Returns the resulting normalized XML string. Note: The function assumes `xmlString` can be type asserted to `string` and may panic otherwise. It is intended for use with valid XML content that needs normalization for consistency or readability.
func SliceFloat64ToInt ¶ added in v0.0.13
SliceFloat64ToInt converts a slice of float64 to a slice of int, truncating the decimal part.
func SliceIntToFloat64 ¶ added in v0.0.13
SliceIntToFloat64 converts a slice of int to a slice of float64.
func SliceMapInterfaceToString ¶ added in v0.0.13
SliceMapInterfaceToString converts a slice of maps with string keys and interface{} values to a slice of maps with string keys and string values. Non-string values will be converted to strings using fmt.Sprint.
func SliceMapStringToInterface ¶ added in v0.0.13
SliceMapStringToInterface converts a slice of maps with string keys and string values to a slice of maps with string keys and interface{} values.
func StringToBytes ¶ added in v0.0.13
StringToBytes converts a string to a byte slice.
func StringToInt ¶ added in v0.0.13
StringToInt converts a string to an int. Returns an error if the conversion is not possible.
func StructToJSON ¶ added in v0.0.13
StructToJSON converts a struct to a JSON string. Returns an error if the conversion is not possible.
Types ¶
This section is empty.