Documentation ¶
Overview ¶
Package util provides generic utilities used throughout the policy engine.
Index ¶
- func BFS(t Traversal, f Iter, u T) bool
- func Backoff(base, max, jitter, factor float64, retries int) time.Duration
- func Close(resp *http.Response)
- func Compare(a, b interface{}) int
- func DFS(t Traversal, f Iter, u T) bool
- func DefaultBackoff(base, max float64, retries int) time.Duration
- func MustMarshalJSON(x interface{}) []byte
- func MustUnmarshalJSON(bs []byte) interface{}
- func NewJSONDecoder(r io.Reader) *json.Decoder
- func Reference(x interface{}) *interface{}
- func RoundTrip(x *interface{}) error
- func Unmarshal(bs []byte, v interface{}) error
- func UnmarshalJSON(bs []byte, x interface{}) (err error)
- func WaitFunc(fun func() bool, interval, timeout time.Duration) error
- type EnumFlag
- type Equals
- type FIFO
- type HashMap
- func (h *HashMap) Copy() *HashMap
- func (h *HashMap) Delete(k T)
- func (h *HashMap) Equal(other *HashMap) bool
- func (h *HashMap) Get(k T) (T, bool)
- func (h *HashMap) Hash() int
- func (h *HashMap) Iter(iter func(T, T) bool) bool
- func (h *HashMap) Len() int
- func (h *HashMap) Put(k T, v T)
- func (h *HashMap) String() string
- func (h *HashMap) Update(other *HashMap) *HashMap
- type Iter
- type LIFO
- type T
- type Traversal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BFS ¶ added in v0.4.9
BFS performs a breadth first traversal calling f for each node starting from u. If f returns true, traversal stops and BFS returns true.
func Backoff ¶ added in v0.8.0
Backoff returns a delay with an exponential backoff based on the number of retries. Same algorithm used in gRPC.
func Close ¶ added in v0.8.0
Close reads the remaining bytes from the response and then closes it to ensure that the connection is freed. If the body is not read and closed, a leak can occur.
func Compare ¶
func Compare(a, b interface{}) int
Compare returns 0 if a equals b, -1 if a is less than b, and 1 if b is than a.
For comparison between values of different types, the following ordering is used: nil < bool < float64 < string < []interface{} < map[string]interface{}. Slices and maps are compared recursively. If one slice or map is a subset of the other slice or map it is considered "less than". Nil is always equal to nil.
func DFS ¶
DFS performs a depth first traversal calling f for each node starting from u. If f returns true, traversal stops and DFS returns true.
func DefaultBackoff ¶ added in v0.8.0
DefaultBackoff returns a delay with an exponential backoff based on the number of retries.
func MustMarshalJSON ¶ added in v0.4.1
func MustMarshalJSON(x interface{}) []byte
MustMarshalJSON returns the JSON encoding of x
If the data cannot be encoded, this function will panic. This function is for test purposes.
func MustUnmarshalJSON ¶ added in v0.4.1
func MustUnmarshalJSON(bs []byte) interface{}
MustUnmarshalJSON parse the JSON encoded data and returns the result.
If the data cannot be decoded, this function will panic. This function is for test purposes.
func NewJSONDecoder ¶ added in v0.3.0
NewJSONDecoder returns a new decoder that reads from r.
This function is intended to be used in place of the standard json.NewDecoder when json.Number is required.
func Reference ¶ added in v0.8.2
func Reference(x interface{}) *interface{}
Reference returns a pointer to its argument unless the argument already is a pointer. If the argument is **t, or ***t, etc, it will return *t.
Used for preparing Go types (including pointers to structs) into values to be put through util.RoundTrip().
func RoundTrip ¶ added in v0.8.0
func RoundTrip(x *interface{}) error
RoundTrip encodes to JSON, and decodes the result again.
Thereby, it is converting its argument to the representation expected by rego.Input and inmem's Write operations. Works with both references and values.
func UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON parses the JSON encoded data and stores the result in the value pointed to by x.
This function is intended to be used in place of the standard json.Marshal function when json.Number is required.
Types ¶
type EnumFlag ¶ added in v0.4.5
type EnumFlag struct {
// contains filtered or unexported fields
}
EnumFlag implements the pflag.Value interface to provide enumerated command line parameter values.
func NewEnumFlag ¶ added in v0.4.5
NewEnumFlag returns a new EnumFlag that has a defaultValue and vs enumerated values.
func (*EnumFlag) Set ¶ added in v0.4.5
Set sets the enum value. If s is not a valid enum value, an error is returned.
type FIFO ¶ added in v0.4.9
type FIFO struct {
// contains filtered or unexported fields
}
FIFO represents a simple FIFO queue.
func NewFIFO ¶ added in v0.4.9
NewFIFO returns a new FIFO queue containing elements ts starting with the left-most argument at the front.
func (*FIFO) Peek ¶ added in v0.4.9
Peek returns the top of the LIFO. If LIFO is empty, returns nil, false.
type HashMap ¶
type HashMap struct {
// contains filtered or unexported fields
}
HashMap represents a key/value map.
func NewHashMap ¶
NewHashMap returns a new empty HashMap.
func (*HashMap) Equal ¶
Equal returns true if this HashMap equals the other HashMap. Two hash maps are equal if they contain the same key/value pairs.
func (*HashMap) Iter ¶
Iter invokes the iter function for each element in the HashMap. If the iter function returns true, iteration stops and the return value is true. If the iter function never returns true, iteration proceeds through all elements and the return value is false.
func (*HashMap) Put ¶
Put inserts a key/value pair into this HashMap. If the key is already present, the existing value is overwritten.
type LIFO ¶ added in v0.4.9
type LIFO struct {
// contains filtered or unexported fields
}
LIFO represents a simple LIFO queue.
func NewLIFO ¶ added in v0.4.9
NewLIFO returns a new LIFO queue containing elements ts starting with the left-most argument at the bottom.
func (*LIFO) Peek ¶ added in v0.4.9
Peek returns the top of the LIFO. If LIFO is empty, returns nil, false.
type Traversal ¶ added in v0.4.9
type Traversal interface { // Edges should return the neighbours of node "u". Edges(u T) []T // Visited should return true if node "u" has already been visited in this // traversal. If the same traversal is used multiple times, the state that // tracks visited nodes should be reset. Visited(u T) bool }
Traversal defines a basic interface to perform traversals.