예제 #1
0
파일: i18n.go 프로젝트: insionng/purine
// 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
}
예제 #2
0
func (s *Server) globalHandler(ctx *tango.Context) {
	param := ctx.Param("*name")
	if param == "favicon.ico" || param == "robots.txt" {
		if !s.serveFiles(ctx, param) {
			ctx.NotFound()
		}
		return
	}

	if !strings.HasPrefix("/"+param, s.prefix) {
		ctx.Redirect(s.prefix)
		return
	}
	param = strings.TrimPrefix("/"+param, s.prefix)
	s.serveFiles(ctx, param)
}
예제 #3
0
func (s *Server) globalHandler(ctx *tango.Context) {
	param := ctx.Param("*name")
	if path.Ext(param) == "" {
		if s.serveFile(ctx, path.Join(s.dstDir, param, "index.html")) {
			return
		}
	}
	if !strings.HasSuffix(param, "/") {
		if s.serveFile(ctx, path.Join(s.dstDir, param, ".html")) {
			return
		}
	}
	if s.serveFile(ctx, path.Join(s.dstDir, param)) {
		return
	}
	ctx.Redirect("/")
}