diff --git a/README.md b/README.md index 9860295b..2d69c5b0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ YoyoGo is a simple, light and fast Web framework written in Go. [![License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) ![Contributors](https://img.shields.io/github/contributors/maxzhang1985/yoyogo.svg) - - # Features - Pretty and fast router - Middleware Support @@ -28,22 +26,28 @@ package main import ... + func main() { - webHost := YoyoGo.CreateDefaultWebHostBuilder(os.Args, RouterConfigFunc).Build() + //webHost := YoyoGo.CreateDefaultWebHostBuilder(os.Args,RouterConfigFunc).Build() + webHost := CreateCustomWebHostBuilder(os.Args).Build() webHost.Run() } - -/* Create the builder of Web host -func CreateCustomWebHostBuilder(args []string) YoyoGo.HostBuilder { +//* Create the builder of Web host +func CreateCustomWebHostBuilder(args []string) *YoyoGo.HostBuilder { return YoyoGo.NewWebHostBuilder(). - UseServer(YoyoGo.DefaultHttps(":8080", "./Certificate/server.pem", "./Certificate/server.key")). + UseFastHttp(":8080"). + //UseServer(YoyoGo.DefaultHttps(":8080", "./Certificate/server.pem", "./Certificate/server.key")). Configure(func(app *YoyoGo.ApplicationBuilder) { app.UseStatic("Static") }). - UseRouter(RouterConfigFunc) + UseRouter(RouterConfigFunc). + ConfigureServices(func(serviceCollection *DependencyInjection.ServiceCollection) { + serviceCollection.AddTransientByImplements(models.NewUserAction, new(models.IUserAction)) + }) } - */ + +//*/ //region router config function func RouterConfigFunc(router Router.IRouterBuilder) { @@ -58,6 +62,42 @@ func RouterConfigFunc(router Router.IRouterBuilder) { }) router.GET("/info", GetInfo) + router.GET("/ioc", GetInfoByIOC) +} + +//endregion + +//region Http Request Methods + +type UserInfo struct { + UserName string `param:"username"` + Number string `param:"q1"` + Id string `param:"id"` +} + +//HttpGet request: /info or /v1/api/info +//bind UserInfo for id,q1,username +func GetInfo(ctx *Context.HttpContext) { + ctx.JSON(200, Std.M{"info": "ok"}) +} + +func GetInfoByIOC(ctx *Context.HttpContext) { + var userAction models.IUserAction + _ = ctx.RequiredServices.GetService(&userAction) + ctx.JSON(200, Std.M{"info": "ok " + userAction.Login("zhang")}) +} + +//HttpPost request: /info/:id ?q1=abc&username=123 +func PostInfo(ctx *Context.HttpContext) { + qs_q1 := ctx.Query("q1") + pd_name := ctx.Param("username") + + userInfo := &UserInfo{} + _ = ctx.Bind(userInfo) + + strResult := fmt.Sprintf("Name:%s , Q1:%s , bind: %s", pd_name, qs_q1, userInfo) + + ctx.JSON(200, Std.M{"info": "hello world", "result": strResult}) } ``` ![](./yoyorun.jpg) @@ -115,8 +155,8 @@ func RouterConfigFunc(router Router.IRouterBuilder) { * [ ] Controller Router And Router Tempalte (Default) ## Dependency injection -* [ ] Dependency injection Framework -* [ ] Dependency injection Integration +* [X] Dependency injection Framework +* [X] Dependency injection Integration ## Features * [ ] swagger