| 149 | } |
| 150 | |
| 151 | func (v Values) pathValue(path []string) (any, error) { |
| 152 | if len(path) == 1 { |
| 153 | // if exists must be root key not table |
| 154 | if _, ok := v[path[0]]; ok && !istable(v[path[0]]) { |
| 155 | return v[path[0]], nil |
| 156 | } |
| 157 | return nil, ErrNoValue{path[0]} |
| 158 | } |
| 159 | |
| 160 | key, path := path[len(path)-1], path[:len(path)-1] |
| 161 | // get our table for table path |
| 162 | t, err := v.Table(joinPath(path...)) |
| 163 | if err != nil { |
| 164 | return nil, ErrNoValue{key} |
| 165 | } |
| 166 | // check table for key and ensure value is not a table |
| 167 | if k, ok := t[key]; ok && !istable(k) { |
| 168 | return k, nil |
| 169 | } |
| 170 | return nil, ErrNoValue{key} |
| 171 | } |
| 172 | |
| 173 | func parsePath(key string) []string { return strings.Split(key, ".") } |
| 174 | |