Skip to content

Commit

Permalink
Dependency injection Framework And Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxzhang committed Dec 2, 2019
1 parent 94faaa3 commit fa89e77
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa89e77

Please sign in to comment.