Esempio n. 1
0
func getAppLangArg(w http.ResponseWriter, r *http.Request) (*App, string) {
	app := getAppArg(w, r)
	if app == nil {
		return nil, ""
	}
	langCode := strings.TrimSpace(r.FormValue("lang"))
	if !store.IsValidLangCode(langCode) {
		httpErrorf(w, "Invalid lang code %q", langCode)
		return nil, ""
	}
	return app, langCode
}
Esempio n. 2
0
// url: /rss?app=$app[&lang=$lang]
func handleRss(w http.ResponseWriter, r *http.Request) {
	appName := strings.TrimSpace(r.FormValue("app"))
	app := findApp(appName)
	if app == nil {
		httpErrorf(w, "Application %q doesn't exist", appName)
		return
	}
	lang := strings.TrimSpace(r.FormValue("lang"))
	if 0 == len(lang) {
		s := getRssAll(app)
		w.Write([]byte(s))
		return
	}

	if !store.IsValidLangCode(lang) {
		httpErrorf(w, "Language %q is not valid", lang)
		return
	}

	w.Write([]byte(getRssForLang(app, lang)))
}
// url: /app/{appname}/{lang}?msg=${msg}
func handleAppTranslations(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	appName := vars["appname"]
	app := findApp(appName)
	if app == nil {
		httpErrorf(w, "Application %q doesn't exist", appName)
		return
	}

	langCode := vars["lang"]
	if !store.IsValidLangCode(langCode) {
		httpErrorf(w, "Invalid language: %q", langCode)
		return
	}
	msg := r.FormValue("msg")
	//fmt.Printf("handleAppTranslations() appName=%s, lang=%s\n", app.Name, langCode)
	model := buildModelAppTranslations(app, langCode, decodeUserFromCookie(r))
	model.Message = msg
	model.RedirectUrl = r.URL.String()
	ExecTemplate(w, tmplAppTrans, model)
}