You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
925 B
Go

package routing
import (
"fmt"
"net/url"
)
// Upstreams holds the base URL for each backend service.
type Upstreams struct {
GameSession string
QuestionBank string
User string
Leaderboard string
Admin string
}
// Validate ensures all upstream URLs are present and valid absolute URLs.
func (u Upstreams) Validate() error {
checks := map[string]string{
"game-session": u.GameSession,
"question-bank": u.QuestionBank,
"user": u.User,
"leaderboard": u.Leaderboard,
"admin": u.Admin,
}
for name, raw := range checks {
if raw == "" {
return fmt.Errorf("%s upstream URL is required", name)
}
parsed, err := url.Parse(raw)
if err != nil {
return fmt.Errorf("invalid %s upstream URL: %w", name, err)
}
if parsed.Scheme == "" || parsed.Host == "" {
return fmt.Errorf("invalid %s upstream URL: must include scheme and host", name)
}
}
return nil
}