From cb0214737a6141501ca3f7cb5730c8594f7d7281 Mon Sep 17 00:00:00 2001 From: yoyofx Date: Tue, 9 Jun 2020 14:47:32 +0800 Subject: [PATCH 1/3] vendor --- README-ZHCN.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README-ZHCN.md b/README-ZHCN.md index 8eaa623e..2aea7076 100644 --- a/README-ZHCN.md +++ b/README-ZHCN.md @@ -23,7 +23,25 @@ YoyoGo 是一个用 Go 编写的简单,轻便,快速的 Web 框架。 ```bash go get github.com/maxzhang1985/yoyogo ``` +# 安装依赖 (由于某些原因国内下载不了依赖) +## go version < 1.13 +```bash +window 下在 cmd 中执行: +set GO111MODULE=on +set GOPROXY=https://goproxy.cn +linux 下执行: +export GO111MODULE=on +export GOPROXY=https://goproxy.cn +``` +## go version >= 1.13 +``` +go env -w GOPROXY=https://goproxy.cn,direct +``` +### vendor +``` +go mod vendor // 将依赖包拷贝到项目目录中去 +``` # 简单的例子 ```golang package main From ea8a7d1031537805c0960347f685702fa8b52407 Mon Sep 17 00:00:00 2001 From: yoyofx Date: Tue, 9 Jun 2020 17:29:43 +0800 Subject: [PATCH 2/3] action list and executor rules --- Router/MvcRouterHandler.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Router/MvcRouterHandler.go b/Router/MvcRouterHandler.go index 2fae845d..3fdf3abc 100644 --- a/Router/MvcRouterHandler.go +++ b/Router/MvcRouterHandler.go @@ -5,11 +5,13 @@ import ( "github.com/maxzhang1985/yoyogo/Context" "github.com/maxzhang1985/yoyogo/Controller" "net/http" + "reflect" "strings" ) type MvcRouterHandler struct { actionFilters []Controller.IActionFilter + actionList map[string]map[string]string } func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents []string) func(ctx *Context.HttpContext) { @@ -29,15 +31,18 @@ func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents panic(controllerName + " controller is not found! " + err.Error()) } + actionMethodExecutor := Controller.NewActionMethodExecutor() executorContext := &Controller.ActionExecutorContext{ ControllerName: controllerName, Controller: controller, ActionName: actionName, Context: ctx, - In: &Controller.ActionExecutorInParam{}, + In: nil, } - actionMethodExecutor := Controller.NewActionMethodExecutor() + executorContext.In = &Controller.ActionExecutorInParam{} + actionResult := actionMethodExecutor.Execute(executorContext) + ctx.SetItem("actionResult", actionResult) return func(ctx *Context.HttpContext) { @@ -64,3 +69,11 @@ func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents } } + +func findControllerAction() { + t := reflect.ValueOf(method.Object) + method.methodInfo = t.MethodByName(method.MethodName) + if !method.methodInfo.IsValid() { + return false + } +} From 2e50563877b44d300af345415011b26d614ded0f Mon Sep 17 00:00:00 2001 From: yoyofx Date: Wed, 10 Jun 2020 12:08:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fixed=20set=20http=20response=20header=20bu?= =?UTF-8?q?gs.=20BUG=E5=87=BA=E7=8E=B0=E5=9C=A8net/http=E4=B8=AD=EF=BC=8Cf?= =?UTF-8?q?asthttp=E6=B2=A1=E6=9C=89=E8=BF=99=E4=B8=AA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82=20=E9=97=AE=E9=A2=98=E6=80=BB=E7=BB=93=EF=BC=9A=20Set?= =?UTF-8?q?=20Header=20->=20Set=20StatusCode=20,=20is=20right.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ActionResult/IActionResult.go | 3 ++- Context/HttpContext.go | 5 ++--- Examples/SimpleWeb/main.go | 1 + Framework/Version.go | 2 +- Router/MvcRouterHandler.go | 15 +++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ActionResult/IActionResult.go b/ActionResult/IActionResult.go index 06e6692e..a7634c66 100644 --- a/ActionResult/IActionResult.go +++ b/ActionResult/IActionResult.go @@ -13,6 +13,7 @@ type IActionResult interface { func writeContentType(w http.ResponseWriter, value []string) { header := w.Header() if val := header["Content-Type"]; len(val) == 0 { - header["Content-Type"] = value + w.Header().Set("content-type", value[0]) + //header["Content-Type"] = value } } diff --git a/Context/HttpContext.go b/Context/HttpContext.go index 44ab52c8..3f66aa76 100644 --- a/Context/HttpContext.go +++ b/Context/HttpContext.go @@ -352,15 +352,14 @@ func bodyAllowedForStatus(status int) bool { // ActionResult writes the response headers and calls render.ActionResult to render data. func (c *HttpContext) Render(code int, r ActionResult.IActionResult) { - c.Status(code) - if !bodyAllowedForStatus(code) { r.WriteContentType(c.Response) c.Response.WriteHeaderNow() return } - if err := r.Render(c.Response); err != nil { + if err := r.Render(c.Response.ResponseWriter); err != nil { panic(err) } + c.Status(code) } diff --git a/Examples/SimpleWeb/main.go b/Examples/SimpleWeb/main.go index f0690e9c..5be38730 100644 --- a/Examples/SimpleWeb/main.go +++ b/Examples/SimpleWeb/main.go @@ -21,6 +21,7 @@ func main() { //* Create the builder of Web host func CreateCustomBuilder() *YoyoGo.HostBuilder { return YoyoGo.NewWebHostBuilder(). + //UseHttp(). UseFastHttp(). //UseServer(YoyoGo.DefaultHttps(":8080", "./Certificate/server.pem", "./Certificate/server.key")). Configure(func(app *YoyoGo.ApplicationBuilder) { diff --git a/Framework/Version.go b/Framework/Version.go index 67238553..127ade76 100644 --- a/Framework/Version.go +++ b/Framework/Version.go @@ -1,5 +1,5 @@ package YoyoGo const ( - Version = "v1.4.9.2 pre-release" + Version = "v1.4.9.3 pre-release" ) diff --git a/Router/MvcRouterHandler.go b/Router/MvcRouterHandler.go index 3fdf3abc..826a16a9 100644 --- a/Router/MvcRouterHandler.go +++ b/Router/MvcRouterHandler.go @@ -5,7 +5,6 @@ import ( "github.com/maxzhang1985/yoyogo/Context" "github.com/maxzhang1985/yoyogo/Controller" "net/http" - "reflect" "strings" ) @@ -70,10 +69,10 @@ func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents } -func findControllerAction() { - t := reflect.ValueOf(method.Object) - method.methodInfo = t.MethodByName(method.MethodName) - if !method.methodInfo.IsValid() { - return false - } -} +//func findControllerAction() { +// t := reflect.ValueOf(method.Object) +// method.methodInfo = t.MethodByName(method.MethodName) +// if !method.methodInfo.IsValid() { +// return false +// } +//}