mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-02-11 17:44:31 +01:00
This is a virtcontainers 1.0.8 import into Kata Containers runtime. virtcontainers is a Go library designed to manage hardware virtualized pods and containers. It is the core Clear Containers framework and will become the core Kata Containers framework, as discussed at https://github.com/kata-containers/runtime/issues/33 Some more more pointers: virtcontainers README, including some design and architecure notes: https://github.com/containers/virtcontainers/blob/master/README.md virtcontainers 1.0 API: https://github.com/containers/virtcontainers/blob/master/documentation/api/1.0/api.md Fixes #40 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package mapstructure
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
// Error implements the error interface and can represents multiple
|
|
// errors that occur in the course of a single decode.
|
|
type Error struct {
|
|
Errors []string
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
points := make([]string, len(e.Errors))
|
|
for i, err := range e.Errors {
|
|
points[i] = fmt.Sprintf("* %s", err)
|
|
}
|
|
|
|
sort.Strings(points)
|
|
return fmt.Sprintf(
|
|
"%d error(s) decoding:\n\n%s",
|
|
len(e.Errors), strings.Join(points, "\n"))
|
|
}
|
|
|
|
// WrappedErrors implements the errwrap.Wrapper interface to make this
|
|
// return value more useful with the errwrap and go-multierror libraries.
|
|
func (e *Error) WrappedErrors() []error {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
|
|
result := make([]error, len(e.Errors))
|
|
for i, e := range e.Errors {
|
|
result[i] = errors.New(e)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func appendErrors(errors []string, err error) []string {
|
|
switch e := err.(type) {
|
|
case *Error:
|
|
return append(errors, e.Errors...)
|
|
default:
|
|
return append(errors, e.Error())
|
|
}
|
|
}
|