mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-28 20:56:11 +01:00
removed resolved todos
This commit is contained in:
parent
2e031a9763
commit
a64ce2feb1
|
@ -68,7 +68,7 @@ func NewPersonId(uri string, source string) (PersonId, error) {
|
||||||
//if !validation.IsValidExternalURL(uri) {
|
//if !validation.IsValidExternalURL(uri) {
|
||||||
// return PersonId{}, fmt.Errorf("uri %s is not a valid external url", 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 {
|
if err != nil {
|
||||||
return PersonId{}, err
|
return PersonId{}, err
|
||||||
}
|
}
|
||||||
|
@ -87,13 +87,12 @@ func NewPersonId(uri string, source string) (PersonId, error) {
|
||||||
return personId, nil
|
return personId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tbd how an which parts can be generalized
|
|
||||||
func NewRepositoryId(uri string, source string) (RepositoryId, error) {
|
func NewRepositoryId(uri string, source string) (RepositoryId, error) {
|
||||||
if !validation.IsAPIURL(uri) {
|
if !validation.IsAPIURL(uri) {
|
||||||
return RepositoryId{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
|
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 {
|
if err != nil {
|
||||||
return RepositoryId{}, err
|
return RepositoryId{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -135,23 +134,3 @@ func IsValidUsername(name string) bool {
|
||||||
|
|
||||||
return validUsernamePatternWithoutDots.MatchString(name) && !invalidUsernamePattern.MatchString(name)
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,23 +8,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
type ValidationFunctions interface {
|
|
||||||
Validate() []string
|
|
||||||
IsValid() (bool, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Validateable struct {
|
|
||||||
ValidationFunctions
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
type Validateable interface {
|
type Validateable interface {
|
||||||
Validate() []string
|
Validate() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsValid(v any) (bool, error) {
|
func IsValid(v Validateable) (bool, error) {
|
||||||
if err := Validate(v); len(err) > 0 {
|
if err := v.Validate(); len(err) > 0 {
|
||||||
errString := strings.Join(err, "\n")
|
errString := strings.Join(err, "\n")
|
||||||
return false, fmt.Errorf(errString)
|
return false, fmt.Errorf(errString)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +21,22 @@ func IsValid(v any) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Validate(v any) []string {
|
func ValidateNotEmpty(value string, fieldName string) []string {
|
||||||
var result = []string{}
|
if value == "" {
|
||||||
return result
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue