// Get retrieves a parameter.
Get retrieves a parameter.
// Get retrieves a parameter .
func (s State) Get(path string) (interface{}, error) {
	parts := strings.Split(path, ".")
	m := s
	for i, part := range parts {
		v, found := m[part]
		if !found {
			return nil, fmt.Errorf("invalid path (key not found): %s", strings.Join(parts[:i+1], "."))
		}
		if i == len(parts)-1 {
			if retMap, ok := v.(map[string]interface{}); ok {
				return State(retMap), nil
			}
			return v, nil
		}
		if newMap, ok := v.(map[string]interface{}); ok {
			m = State(newMap)
			continue
		}
		return nil, fmt.Errorf("invalid path (key isn't a map): %s", strings.Join(parts[:i+1], "."))
	}
	return nil, fmt.Errorf("invalid path (eek!): %s", path)
}
func ( s State ) Get ( path string ) ( interface { } , error ) { parts := strings . Split ( path , " " ) m := s for i , part := range parts { v , found := m [ part ] if ! found { return nil , fmt . Errorf ( " " , strings . Join ( parts [ : i + 1 ] , " " ) ) } if i == len ( parts ) - 1 { if retMap , ok := v . ( map [ string ] interface { } ) ; ok { return State ( retMap ) , nil } return v , nil } if newMap , ok := v . ( map [ string ] interface { } ) ; ok { m = State ( newMap ) continue } return nil , fmt . Errorf ( " " , strings . Join ( parts [ : i + 1 ] , " " ) ) } return nil , fmt . Errorf ( " " , path ) }
Get retrieves a parameter.
Get retrieves a parameter .
// Found the value! // When the value is a sub-object (as opposed to a primitive value), we box // it into a State to keep the nice property that a sub-tree of State is // still a State. // We can only continue if we're traversing a map. // We shouldn't reach this.