// getInterfaceValue will return an interface{} with an appropriate type for the puppetType // NOTE: This is *very* basic and will revert to just returning the string value by default. func getInterfaceValue(puppetType string, val string) (retVal interface{}) { var err error if val == "" { return nil // Don't set a parameter that is "" (empty) } // Handle Optional[WHATEVER] if strings.HasPrefix(puppetType, "Optional[") { puppetType = strings.TrimPrefix(puppetType, "Optional[") puppetType = strings.TrimSuffix(puppetType, "]") return getInterfaceValue(puppetType, val) } if puppetType == "Integer" { retVal, err = strconv.Atoi(val) if err != nil { log.WithField("val", val).Error("Error converting to integer: ", err) return nil } return } if puppetType == "Boolean" { switch val { case "yes", "true", "1": return true default: return false } } // Otherwise just return the "string" (shrug) return val }