mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 05:47:57 +00:00
added validation for settings
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidGitHubTrailingSlash = errors.New("GitHub URL should not have a trailing slash")
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
@@ -38,3 +44,13 @@ func (s *Settings) URL() *url.URL {
|
||||
Scheme: s.Scheme,
|
||||
Host: s.Domain}
|
||||
}
|
||||
|
||||
// Validate verifies all required fields are correctly populated.
|
||||
func (s *Settings) Validate() error {
|
||||
switch {
|
||||
case strings.HasSuffix(s.GitHubApiUrl, "/"):
|
||||
return ErrInvalidGitHubTrailingSlash
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user