mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-15 08:41:16 -05:00
Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 1.4.2 to 1.5.0. - [Release notes](https://github.com/open-policy-agent/opa/releases) - [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-policy-agent/opa/compare/v1.4.2...v1.5.0) --- updated-dependencies: - dependency-name: github.com/open-policy-agent/opa dependency-version: 1.5.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
73 lines
1.2 KiB
Go
73 lines
1.2 KiB
Go
package ast
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
var _ json.Unmarshaler = (*Path)(nil)
|
|
|
|
type Path []PathElement
|
|
|
|
type PathElement interface {
|
|
isPathElement()
|
|
}
|
|
|
|
var (
|
|
_ PathElement = PathIndex(0)
|
|
_ PathElement = PathName("")
|
|
)
|
|
|
|
func (path Path) String() string {
|
|
if path == nil {
|
|
return ""
|
|
}
|
|
var str bytes.Buffer
|
|
for i, v := range path {
|
|
switch v := v.(type) {
|
|
case PathIndex:
|
|
str.WriteString(fmt.Sprintf("[%d]", v))
|
|
case PathName:
|
|
if i != 0 {
|
|
str.WriteByte('.')
|
|
}
|
|
str.WriteString(string(v))
|
|
default:
|
|
panic(fmt.Sprintf("unknown type: %T", v))
|
|
}
|
|
}
|
|
return str.String()
|
|
}
|
|
|
|
func (path *Path) UnmarshalJSON(b []byte) error {
|
|
var vs []interface{}
|
|
err := json.Unmarshal(b, &vs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*path = make([]PathElement, 0, len(vs))
|
|
for _, v := range vs {
|
|
switch v := v.(type) {
|
|
case string:
|
|
*path = append(*path, PathName(v))
|
|
case int:
|
|
*path = append(*path, PathIndex(v))
|
|
case float64:
|
|
*path = append(*path, PathIndex(int(v)))
|
|
default:
|
|
return fmt.Errorf("unknown path element type: %T", v)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type PathIndex int
|
|
|
|
func (PathIndex) isPathElement() {}
|
|
|
|
type PathName string
|
|
|
|
func (PathName) isPathElement() {}
|