experiment on generalization
This commit is contained in:
parent
75cc5b900d
commit
6e4467d49d
2 changed files with 64 additions and 32 deletions
32
modules/validation/validateable.go
Normal file
32
modules/validation/validateable.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2023 The forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ValidationFunctions interface {
|
||||
Validate() []string
|
||||
IsValid() (bool, error)
|
||||
}
|
||||
|
||||
type Validateable struct {
|
||||
ValidationFunctions
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue