added validation for settings

This commit is contained in:
Brad Rydzewski
2014-02-21 15:25:05 -07:00
parent 3c25a4a00a
commit 6410bdbe9d
2 changed files with 18 additions and 2 deletions

View File

@@ -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
}
}