landing.go (1231B)
1 package web 2 3 import ( 4 "net/http" 5 "net/url" 6 "strings" 7 ) 8 9 type landingContent struct { 10 Currency string 11 BankRegisterURL string 12 BankPublicAccountsURL string 13 BlogURL string 14 DonationsURL string 15 } 16 17 func (a *App) registerLandingRoutes() { 18 a.handleGet("/{lang}/{$}", a.landing) 19 } 20 21 func (a *App) landing(w http.ResponseWriter, r *http.Request) { 22 lang := r.PathValue("lang") 23 if !validLocale(lang) { 24 a.renderError(w, r, http.StatusNotFound, "en", "Page not found", nil) 25 return 26 } 27 bank := strings.TrimRight(a.opts.PublicURLs.Bank, "/") 28 bankRegister := "#" 29 bankPublic := "#" 30 if bank != "" { 31 bankRegister = bank 32 bankPublic = bank + "#public-accounts" 33 } 34 localizedMerchant := func(base string) string { 35 base = strings.TrimRight(base, "/") 36 if base == "" { 37 return "#" 38 } 39 return base + "/" + url.PathEscape(lang) 40 } 41 content := landingContent{ 42 Currency: a.opts.Currency, BankRegisterURL: bankRegister, 43 BankPublicAccountsURL: bankPublic, 44 BlogURL: localizedMerchant(a.opts.PublicURLs.Blog), 45 DonationsURL: localizedMerchant(a.opts.PublicURLs.Donations), 46 } 47 a.render(w, "landing", a.makePage(r, lang, "GNU Taler Demo", content), http.StatusOK) 48 }