Pass the context from app to locale.mustGetAvailableLanguages
There is no reason for that function to know the context.
This commit is contained in:
parent
dd0a4a8ba9
commit
ca4ecd3a3e
|
@ -6,6 +6,7 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
@ -28,7 +29,7 @@ type App struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db *database.DB, avatarsDir string) (http.Handler, error) {
|
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"))
|
static := http.FileServer(http.Dir("web/static"))
|
||||||
profile, err := newProfileHandler(static, avatarsDir)
|
profile, err := newProfileHandler(static, avatarsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -31,8 +31,8 @@ func (m Locales) Tags() []language.Tag {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustGetAll(db *database.DB) Locales {
|
func MustGetAll(ctx context.Context, db *database.DB) Locales {
|
||||||
availableLanguages := mustGetAvailableLanguages(db)
|
availableLanguages := mustGetAvailableLanguages(ctx, db)
|
||||||
locales := map[language.Tag]*Locale{}
|
locales := map[language.Tag]*Locale{}
|
||||||
for _, lang := range availableLanguages {
|
for _, lang := range availableLanguages {
|
||||||
locale := newLocale(lang)
|
locale := newLocale(lang)
|
||||||
|
@ -85,8 +85,8 @@ type availableLanguage struct {
|
||||||
currencyPattern string
|
currencyPattern string
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustGetAvailableLanguages(db *database.DB) []availableLanguage {
|
func mustGetAvailableLanguages(ctx context.Context, db *database.DB) []availableLanguage {
|
||||||
rows, err := db.Query(context.Background(), "select lang_tag, currency_pattern from language where selectable")
|
rows, err := db.Query(ctx, "select lang_tag, currency_pattern from language where selectable")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue