Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-28 20:56:11 +01:00

removed resolved todos

This commit is contained in:
Michael Jerger 2023-12-22 14:20:30 +01:00
parent 2e031a9763
commit a64ce2feb1
3 changed files with 22 additions and 40 deletions

View file

@ -68,7 +68,7 @@ func NewPersonId(uri string, source string) (PersonId, error) {
//if !validation.IsValidExternalURL(uri) {
// return PersonId{}, fmt.Errorf("uri %s is not a valid external url", uri)
//}
validatedUri, err := url.ParseRequestURI(uri) // ToDo: Why no err treatment at this place?
validatedUri, err := url.ParseRequestURI(uri)
if err != nil {
return PersonId{}, err
}
@ -87,13 +87,12 @@ func NewPersonId(uri string, source string) (PersonId, error) {
return personId, nil
}
// TODO: tbd how an which parts can be generalized
func NewRepositoryId(uri string, source string) (RepositoryId, error) {
if !validation.IsAPIURL(uri) {
return RepositoryId{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
}
validatedUri, err := url.ParseRequestURI(uri) // ToDo: Why no err treatment at this place?
validatedUri, err := url.ParseRequestURI(uri)
if err != nil {
return RepositoryId{}, err
}

View file

@ -4,7 +4,6 @@
package validation
import (
"fmt"
"net"
"net/url"
"regexp"
@ -135,23 +134,3 @@ func IsValidUsername(name string) bool {
return validUsernamePatternWithoutDots.MatchString(name) && !invalidUsernamePattern.MatchString(name)
}
func ValidateNotEmpty(value string, fieldName string) []string {
if value == "" {
return []string{fmt.Sprintf("Field %v may not be empty", fieldName)}
}
return []string{}
}
func ValidateOneOf(value string, allowed []string) []string {
for _, allowedElem := range allowed {
if value == allowedElem {
return []string{}
}
}
return []string{fmt.Sprintf("Value %v is not contained in allowed values [%v]", value, allowed)}
}
func ValidateSuffix(str, suffix string) bool {
return strings.HasSuffix(str, suffix)
}

View file

@ -8,23 +8,12 @@ import (
"strings"
)
/*
type ValidationFunctions interface {
Validate() []string
IsValid() (bool, error)
}
type Validateable struct {
ValidationFunctions
}
*/
type Validateable interface {
Validate() []string
}
func IsValid(v any) (bool, error) {
if err := Validate(v); len(err) > 0 {
func IsValid(v Validateable) (bool, error) {
if err := v.Validate(); len(err) > 0 {
errString := strings.Join(err, "\n")
return false, fmt.Errorf(errString)
}
@ -32,7 +21,22 @@ func IsValid(v any) (bool, error) {
return true, nil
}
func Validate(v any) []string {
var result = []string{}
return result
func ValidateNotEmpty(value string, fieldName string) []string {
if value == "" {
return []string{fmt.Sprintf("Field %v may not be empty", fieldName)}
}
return []string{}
}
func ValidateOneOf(value string, allowed []string) []string {
for _, allowedElem := range allowed {
if value == allowedElem {
return []string{}
}
}
return []string{fmt.Sprintf("Value %v is not contained in allowed values [%v]", value, allowed)}
}
func ValidateSuffix(str, suffix string) bool {
return strings.HasSuffix(str, suffix)
}