forgejo/modules/validation/validateable.go

39 lines
591 B
Go
Raw Normal View History

2023-12-22 10:48:24 +00:00
// Copyright 2023 The forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package validation
import (
"fmt"
"strings"
)
2023-12-22 12:44:45 +00:00
/*
2023-12-22 10:48:24 +00:00
type ValidationFunctions interface {
Validate() []string
IsValid() (bool, error)
}
type Validateable struct {
ValidationFunctions
}
2023-12-22 12:44:45 +00:00
*/
type Validateable interface {
Validate() []string
}
2023-12-22 10:48:24 +00:00
func IsValid(v any) (bool, error) {
if err := Validate(v); len(err) > 0 {
errString := strings.Join(err, "\n")
return false, fmt.Errorf(errString)
}
return true, nil
}
func Validate(v any) []string {
var result = []string{}
return result
}