// GetConfigEntry reads the lenses back-end configuration and sets the value of a key, based on "keys", to the "outPtr".
GetConfigEntry reads the lenses back-end configuration and sets the value of a key, based on "keys", to the "outPtr".
// GetConfigEntry reads the lenses back - end configuration and sets the value of a key based on " keys " to the " outPtr " .
func (c *Client) GetConfigEntry(outPtr interface{}, keys ...string) error {
	config := make(map[string]interface{})
	err := c.getBoxConfig(&config)
	if err != nil || len(config) == 0 {
		return fmt.Errorf("[%s]: cannot be extracted: unable to retrieve the config: [%v]", keys, err)
	}
	for i, key := range keys {
		raw, ok := config[key]
		if !ok { 
			if isLast := len(keys)-1 == i; !isLast {
				continue
			}
			return fmt.Errorf("[%s]: couldn't find the corresponding key from config", key)
		}
		if strPtr, ok := outPtr.(*string); ok {
			strValue, ok := raw.(string)
			if !ok {
				return fmt.Errorf("[%s]: [%v] not type of string", key, raw)
			}
			if len(strValue) == 0 {
				return nil
			}
			*strPtr = strValue
			return nil
		}
		if intPtr, ok := outPtr.(*int); ok {
			intValue, ok := raw.(int)
			if !ok {
				return fmt.Errorf("[%s]: [%v] not type of int", key, raw)
			}
			*intPtr = intValue
			return err
		}
		b, err := json.Marshal(raw)
		if err != nil {
			return err
		}
		if len(b) <= 2 {
			return nil
		}
		if err = json.Unmarshal(b, outPtr); err != nil {
			return fmt.Errorf("[%s]: json unarshal of: [%s]: [%v]", key, string(b), err)
		}
		return nil
	}
	return nil
}
func ( c * Client ) GetConfigEntry ( outPtr interface { } , keys ... string ) error { config := make ( map [ string ] interface { } ) err := c . getBoxConfig ( & config ) if err != nil || len ( config ) == 0 { return fmt . Errorf ( " " , keys , err ) } for i , key := range keys { raw , ok := config [ key ] if ! ok { if isLast := len ( keys ) - 1 == i ; ! isLast { continue } return fmt . Errorf ( " " , key ) } if strPtr , ok := outPtr . ( * string ) ; ok { strValue , ok := raw . ( string ) if ! ok { return fmt . Errorf ( " " , key , raw ) } if len ( strValue ) == 0 { return nil } * strPtr = strValue return nil } if intPtr , ok := outPtr . ( * int ) ; ok { intValue , ok := raw . ( int ) if ! ok { return fmt . Errorf ( " " , key , raw ) } * intPtr = intValue return err } b , err := json . Marshal ( raw ) if err != nil { return err } if len ( b ) <= 2 { return nil } if err = json . Unmarshal ( b , outPtr ) ; err != nil { return fmt . Errorf ( " " , key , string ( b ) , err ) } return nil } return nil }
GetConfigEntry reads the lenses back-end configuration and sets the value of a key, based on "keys", to the "outPtr".
GetConfigEntry reads the lenses back - end configuration and sets the value of a key based on " keys " to the " outPtr " .
// support many tries. // check for existence. // config key found, now exit on the first failure. // safe cast to string. // if the outPtr is a raw string, then set it as it's. // safe cast to int. // if the outPtr is a raw int, then set it as int. // otherwise convert that raw interface to bytes, unmarshal it and set it. // if empty object or empty list or empty quoted string. // fixes // lenses.sql.connect.clusters: json unarshal of: '""': json: cannot unmarshal string into Go value of type // []lenses.ConnectCluster