Pass the context from app to locale.mustGetAvailableLanguages

There is no reason for that function to know the context.
This commit is contained in:
jordi fita mas 2023-08-06 04:04:36 +02:00
parent dd0a4a8ba9
commit ca4ecd3a3e
2 changed files with 6 additions and 5 deletions

View File

@ -6,6 +6,7 @@
package app
import (
"context"
"net/http"
"golang.org/x/text/language"
@ -28,7 +29,7 @@ type App struct {
}
func New(db *database.DB, avatarsDir string) (http.Handler, error) {
locales := locale.MustGetAll(db)
locales := locale.MustGetAll(context.Background(), db)
static := http.FileServer(http.Dir("web/static"))
profile, err := newProfileHandler(static, avatarsDir)
if err != nil {

View File

@ -31,8 +31,8 @@ func (m Locales) Tags() []language.Tag {
return keys
}
func MustGetAll(db *database.DB) Locales {
availableLanguages := mustGetAvailableLanguages(db)
func MustGetAll(ctx context.Context, db *database.DB) Locales {
availableLanguages := mustGetAvailableLanguages(ctx, db)
locales := map[language.Tag]*Locale{}
for _, lang := range availableLanguages {
locale := newLocale(lang)
@ -85,8 +85,8 @@ type availableLanguage struct {
currencyPattern string
}
func mustGetAvailableLanguages(db *database.DB) []availableLanguage {
rows, err := db.Query(context.Background(), "select lang_tag, currency_pattern from language where selectable")
func mustGetAvailableLanguages(ctx context.Context, db *database.DB) []availableLanguage {
rows, err := db.Query(ctx, "select lang_tag, currency_pattern from language where selectable")
if err != nil {
panic(err)
}