utilities

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64EncodeIfNot added in v0.0.11

func Base64EncodeIfNot(value string) string

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

func BytesToString(b []byte) string

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

func ConvertSlice[T any, U any](s []T, convert func(T) U) []U

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

func DecodePlistToCustomType(data []byte, customType *plistCustomType) (int, error)

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

func DecodePlistToMap(data []byte) (map[string]interface{}, int, error)

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

func DecodeXmlString(s string) string

DecodeXmlString unescapes HTML entities in a string back to their original XML special characters.

func EncodeCustomTypeToPlist added in v0.0.11

func EncodeCustomTypeToPlist(customType plistCustomType, format int) error

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

func EncodeMapToPlist(data map[string]interface{}, format int) error

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

func EncodeXmlString(s string) string

EncodeXmlString escapes special XML characters in a string and replaces them with their corresponding HTML entities.

func ExtractSetToStringSlice added in v0.0.13

func ExtractSetToStringSlice(set *schema.Set) []string

Helper function to extract string slice from *schema.Set

func Float64ToInt added in v0.0.13

func Float64ToInt(f float64) int

Float64ToInt converts a float64 to an int, truncating the decimal part.

func GetStringValueFromMap added in v0.0.13

func GetStringValueFromMap(m map[string]interface{}, key string) (string, bool)

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

func IntToFloat64(i int) float64

IntToFloat64 converts an int to a float64.

func IntToString added in v0.0.13

func IntToString(i int) string

IntToString converts an int to a string.

func JSONToStruct added in v0.0.13

func JSONToStruct(data string, v interface{}) error

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

func MapInterfaceToString(m map[string]interface{}) map[string]string

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

func MapStringToInterface(m map[string]string) map[string]interface{}

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

func SliceFloat64ToInt(slice []float64) []int

SliceFloat64ToInt converts a slice of float64 to a slice of int, truncating the decimal part.

func SliceIntToFloat64 added in v0.0.13

func SliceIntToFloat64(slice []int) []float64

SliceIntToFloat64 converts a slice of int to a slice of float64.

func SliceMapInterfaceToString added in v0.0.13

func SliceMapInterfaceToString(slice []map[string]interface{}) []map[string]string

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

func SliceMapStringToInterface(slice []map[string]string) []map[string]interface{}

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

func StringToBytes(s string) []byte

StringToBytes converts a string to a byte slice.

func StringToInt added in v0.0.13

func StringToInt(s string) (int, error)

StringToInt converts a string to an int. Returns an error if the conversion is not possible.

func StructToJSON added in v0.0.13

func StructToJSON(v interface{}) (string, error)

StructToJSON converts a struct to a JSON string. Returns an error if the conversion is not possible.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL