Compatible with revel 0.18

This commit is contained in:
lealife
2017-11-30 18:10:59 +08:00
parent 430744a324
commit c6937fd184
11 changed files with 152 additions and 74 deletions

View File

@ -104,7 +104,7 @@ func (r *RenderTemplateResult) Apply(req *revel.Request, resp *revel.Response) {
chunked := revel.Config.BoolDefault("results.chunked", false)
// If it's a HEAD request, throw away the bytes.
out := io.Writer(resp.Out)
out := io.Writer(resp.GetWriter())
if req.Method == "HEAD" {
out = ioutil.Discard
}
@ -289,7 +289,7 @@ func (r ErrorResult) Apply(req *revel.Request, resp *revel.Response) {
// 不是preview就不要显示错误了
if r.IsPreview {
var b bytes.Buffer
out := io.Writer(resp.Out)
out := io.Writer(resp.GetWriter())
// out = ioutil.Discard
err = tmpl.Execute(&b, r.ViewArgs)
resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")

View File

@ -210,10 +210,10 @@ func hasAcceptLanguageHeader(request *revel.Request) (bool, string) {
// Determine whether the given request has a valid language cookie value.
func hasLocaleCookie(request *revel.Request) (bool, string) {
if request != nil && request.Cookies() != nil {
if request != nil {
name := revel.Config.StringDefault(localeCookieConfigKey, revel.CookiePrefix+"_LANG")
if cookie, error := request.Cookie(name); error == nil {
return true, cookie.Value
return true, cookie.GetValue()
} else {
revel.TRACE.Printf("Unable to read locale cookie with name '%s': %s", name, error.Error())
}

View File

@ -3,7 +3,7 @@ package route
import (
"github.com/leanote/leanote/app/db"
"github.com/revel/revel"
// . "github.com/leanote/leanote/app/lea"
. "github.com/leanote/leanote/app/lea"
"net/url"
"strings"
)
@ -14,15 +14,19 @@ var staticPrefix = []string{"/public", "/favicon.ico", "/css", "/js", "/images",
func RouterFilter(c *revel.Controller, fc []revel.Filter) {
// 补全controller部分
path := c.Request.Request.URL.Path
path := c.Request.URL.Path
// Figure out the Controller/Action
var route *revel.RouteMatch = revel.MainRouter.Route(c.Request.Request)
// var route *revel.RouteMatch = revel.MainRouter.Route(c.Request.Request)
route := revel.MainRouter.Route(c.Request)
if route == nil {
c.Result = c.NotFound("No matching route found: " + c.Request.RequestURI)
c.Result = c.NotFound("No matching route found: " + c.Request.GetRequestURI())
return
}
Log("---------" + route.Action + " " + path)
// The route may want to explicitly return a 404.
if route.Action == "404" {
c.Result = c.NotFound("(intentionally)")
@ -47,14 +51,23 @@ func RouterFilter(c *revel.Controller, fc []revel.Filter) {
// 检查mongodb 是否lost
db.CheckMongoSessionLost()
// /api/file/getImage -> App\file (/api/file/getImage)
// App\auth
// App\note
// static\static
//
// Log("---------" + route.ControllerName + " " + path)
// api设置
// leanote.com/api/user/get => ApiUser::Get
//* /api/login ApiAuth.Login, 这里的设置, 其实已经转成了ApiAuth了
if strings.HasPrefix(path, "/api") && !strings.HasPrefix(route.ControllerName, "Api") {
route.ControllerName = "Api" + route.ControllerName
} else if strings.HasPrefix(path, "/member") && !strings.HasPrefix(route.ControllerName, "Member") {
if strings.HasPrefix(path, "/api") && !strings.HasPrefix(route.ControllerName, "App\\api") {
route.ControllerName = "App\\api" + strings.Split(route.ControllerName, "\\")[1]
// route.ControllerName = "App\\apifile"
} else if strings.HasPrefix(path, "/member") && !strings.HasPrefix(route.ControllerName, "App\\member") {
// member设置
route.ControllerName = "Member" + route.ControllerName
// route.ControllerName = "App\\Member" + route.ControllerName
route.ControllerName = "App\\member" + strings.Split(route.ControllerName, "\\")[1]
}
// end
}