Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boot routing and match the request #10

Merged
merged 6 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#9 implement controller type
  • Loading branch information
Reindert Vetter committed Dec 2, 2019
commit e85cbf915ce427bc3e62bcf640ff2b702ebca66d
4 changes: 4 additions & 0 deletions foundation/http/controllers/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package controllers

type Controller struct {
}
1 change: 1 addition & 0 deletions foundation/http/controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import "lanvard/http"

type User struct {
Controller
}

func (u User) Index(request http.Request) http.Response {
Expand Down
6 changes: 3 additions & 3 deletions foundation/http/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type Kernel struct {
App foundation.Application
Router routing.Router
Router router.Router
Middleware []middleware.PipeInterface
}

Expand Down Expand Up @@ -38,7 +38,7 @@ func (k Kernel) Bootstrap() foundation.Application {
}

func (k Kernel) dispatchToRouter() middleware.Destination {
return func(app foundation.Application, request http.Request) http.Response {
return router.NewRouter(app).DispatchToRoute(request)
return func(request http.Request) http.Response {
return router.NewRouter(k.App).DispatchToRoute(request)
}
}
3 changes: 2 additions & 1 deletion routing/router/methods.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package router

import (
"lanvard/foundation/http/controllers"
"lanvard/http"
net "net/http"
)

type ControllerMethod func(interface{}, http.Request) http.Response
type ControllerMethod func(controllers.Controller, http.Request) http.Response

// All of the methods supported by the router.
var allMethods = []string{
Expand Down
2 changes: 2 additions & 0 deletions routing/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package router

import (
"lanvard/foundation"
"lanvard/foundation/http/controllers"
"lanvard/http"
)

Expand All @@ -24,5 +25,6 @@ func (r Router) DispatchToRoute(request http.Request) http.Response {
// todo implement event Events\RouteMatched
// todo implement RouteMiddleware
// todo remove nil
var nil controllers.Controller
return route.Controller(nil, request)
}
4 changes: 2 additions & 2 deletions src/app/http/middleware/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
type Passable = http.Request
type Result = http.Response

type Destination func(app foundation.Application, data Passable) Result
type Destination func(data Passable) Result
type PipeInterface interface {
Handle(data Passable, next func(data Passable) Result) Result
Handle(data Passable, next Destination) Result
}

// noinspection GoNameStartsWithPackageName
Expand Down