mirror of
https://github.com/bytedream/docker4ssh.git
synced 2025-05-09 12:15:11 +02:00
46 lines
940 B
Go
46 lines
940 B
Go
package validate
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/docker/docker/client"
|
|
"strings"
|
|
)
|
|
|
|
type Validator struct {
|
|
Cli *client.Client
|
|
Strict bool
|
|
}
|
|
|
|
type ValidatorResult struct {
|
|
Strict bool
|
|
|
|
Errors []*ValidateError
|
|
}
|
|
|
|
func (vr *ValidatorResult) Ok() bool {
|
|
return len(vr.Errors) == 0
|
|
}
|
|
|
|
func (vr *ValidatorResult) String() string {
|
|
builder := strings.Builder{}
|
|
|
|
if len(vr.Errors) == 0 {
|
|
if vr.Strict {
|
|
builder.WriteString("Validated all files, no errors were found. You're good to go (strict mode on)")
|
|
} else {
|
|
builder.WriteString("Validated all files, no errors were found. You're good to go")
|
|
}
|
|
} else {
|
|
if vr.Strict {
|
|
builder.WriteString(fmt.Sprintf("Found %d errors (strict mode on)\n\n", len(vr.Errors)))
|
|
} else {
|
|
builder.WriteString(fmt.Sprintf("Found %d errors\n\n", len(vr.Errors)))
|
|
}
|
|
for _, err := range vr.Errors {
|
|
builder.WriteString(fmt.Sprintf("%v\n", err))
|
|
}
|
|
}
|
|
|
|
return builder.String()
|
|
}
|