Skip to content

Commit a16592b

Browse files
authored
Centralise hardcoded constants into named symbols (#48)
Fixes #31 — collects scattered magic values into one place: - internal/site/config.go: BaseURL, ArchiveURL, HTTPTimeout - internal/ui/commands.go: cmdTimeout (20s, stays near command layer) client.go and update.go now reference the named constants instead of inline literals.
1 parent 416376b commit a16592b

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

internal/site/client.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@ import (
77
"io"
88
"net/http"
99
"net/url"
10-
"time"
1110

1211
"github.com/PuerkitoBio/goquery"
1312
"golang.org/x/net/html/charset"
1413
)
1514

16-
const defaultBaseURL = "http://www.90minut.pl"
17-
1815
type Client struct {
1916
baseURL *url.URL
2017
http *http.Client
2118
}
2219

2320
func NewClient() *Client {
24-
base, _ := url.Parse(defaultBaseURL)
21+
base, _ := url.Parse(BaseURL)
2522

2623
return &Client{
2724
baseURL: base,
2825
http: &http.Client{
29-
Timeout: 15 * time.Second,
26+
Timeout: HTTPTimeout,
3027
},
3128
}
3229
}

internal/site/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package site
2+
3+
import "time"
4+
5+
const (
6+
BaseURL = "http://www.90minut.pl"
7+
ArchiveURL = BaseURL + "/archsezon.php"
8+
9+
// HTTPTimeout caps individual HTTP round-trips; kept short to surface
10+
// connectivity failures quickly without blocking the TUI.
11+
HTTPTimeout = 15 * time.Second
12+
)

internal/ui/commands.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import (
1010
"github.com/adrunkhuman/90minuTUI/internal/site"
1111
)
1212

13+
// cmdTimeout is generous enough for slow archive pages without blocking the TUI indefinitely.
14+
const cmdTimeout = 20 * time.Second
15+
1316
func (m Model) loadArchiveCmd(url string) tea.Cmd {
1417
return func() tea.Msg {
15-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
18+
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
1619
defer cancel()
1720
seasons, selectedIdx, competitions, err := m.service.LoadArchive(ctx, url)
1821
return archiveLoadedMsg{seasons: seasons, selectedIdx: selectedIdx, competitions: competitions, err: err}
@@ -21,7 +24,7 @@ func (m Model) loadArchiveCmd(url string) tea.Cmd {
2124

2225
func (m Model) loadSeasonCompetitionsCmd(url, seasonKey string) tea.Cmd {
2326
return func() tea.Msg {
24-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
27+
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
2528
defer cancel()
2629
_, _, competitions, err := m.service.LoadArchive(ctx, url)
2730
return competitionsLoadedMsg{seasonKey: seasonKey, competitions: competitions, err: err}
@@ -30,7 +33,7 @@ func (m Model) loadSeasonCompetitionsCmd(url, seasonKey string) tea.Cmd {
3033

3134
func (m Model) loadCompetitionCmd(url, competitionKey string) tea.Cmd {
3235
return func() tea.Msg {
33-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
36+
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
3437
defer cancel()
3538
menu, league, err := m.service.LoadCompetition(ctx, url)
3639
return competitionMenuLoadedMsg{competitionKey: competitionKey, menu: menu, league: league, err: err}
@@ -39,7 +42,7 @@ func (m Model) loadCompetitionCmd(url, competitionKey string) tea.Cmd {
3942

4043
func (m Model) loadLeagueCmd(url, competitionKey string) tea.Cmd {
4144
return func() tea.Msg {
42-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
45+
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
4346
defer cancel()
4447
league, err := m.service.LoadLeague(ctx, url)
4548
return leagueLoadedMsg{competitionKey: competitionKey, league: league, err: err}
@@ -48,7 +51,7 @@ func (m Model) loadLeagueCmd(url, competitionKey string) tea.Cmd {
4851

4952
func (m Model) loadMatchCmd(url, fixtureKey string) tea.Cmd {
5053
return func() tea.Msg {
51-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
54+
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
5255
defer cancel()
5356
match, err := m.service.LoadMatch(ctx, url)
5457
return matchLoadedMsg{fixtureKey: fixtureKey, match: match, err: err}

internal/ui/update.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"time"
55

66
tea "github.com/charmbracelet/bubbletea"
7+
8+
"github.com/adrunkhuman/90minuTUI/internal/site"
79
)
810

911
func (m Model) Init() tea.Cmd {
10-
return m.loadArchiveCmd("http://www.90minut.pl/archsezon.php")
12+
return m.loadArchiveCmd(site.ArchiveURL)
1113
}
1214

1315
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -391,7 +393,7 @@ func (m *Model) handleReload() tea.Cmd {
391393

392394
m.match = nil
393395
if len(m.seasons) == 0 {
394-
return m.loadArchiveCmd("http://www.90minut.pl/archsezon.php")
396+
return m.loadArchiveCmd(site.ArchiveURL)
395397
}
396398

397399
if m.selectorActive() && m.focus == focusSeasons {

0 commit comments

Comments
 (0)