File: segment.go

package info (click to toggle)
golang-github-caspr-io-yamlpath 0.0~git20200722.502e8d1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116 kB
  • sloc: makefile: 11
file content (19 lines) | stat: -rw-r--r-- 476 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package segments

import "fmt"

type YamlPathSegment interface {
	NavigateMap(map[string]interface{}) (interface{}, error)
	NavigateArray([]interface{}) (interface{}, error)
}

func NavigateYaml(yaml interface{}, segment YamlPathSegment) (interface{}, error) {
	switch y := yaml.(type) {
	case map[string]interface{}:
		return segment.NavigateMap(y)
	case []interface{}:
		return segment.NavigateArray(y)
	default:
		return nil, fmt.Errorf("no support yet for %v", yaml)
	}
}