// get language from context func getContextLanguage(ctx *tango.Context) string { // get from cookie lang := ctx.Cookie(langCookieName) // get from header if lang == "" { al := ctx.Req().Header.Get("Accept-Language") if len(al) > 4 { lang = al[:5] // Only compare first 5 letters. } } // get from query param if lang == "" { lang = ctx.Param(langParamName) } // get default if not find in context lang = strings.ToLower(lang) if !i18n.IsExist(lang) { lang = i18n.GetLangByIndex(0) } return lang }
// get auth token via http header, cookie or form value func (ar *AuthRouter) GetAuthToken(ctx *tango.Context) string { var token string if token = ctx.Header().Get("X-Token"); token != "" { return token } if token = ctx.Cookie("x-token"); token != "" { return token } return ctx.Form("x-token") }