-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from lanvard/develop
Boot routing and match the request
- Loading branch information
Showing
27 changed files
with
468 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package controllers | ||
|
||
import ( | ||
"lanvard/http" | ||
"lanvard/routing" | ||
) | ||
|
||
var User = struct { | ||
Index routing.ControllerMethod | ||
Store routing.ControllerMethod | ||
Destroy routing.ControllerMethod | ||
}{ | ||
Index: func(request http.Request) http.Response { | ||
return http.Json("{\"test Index\": 123}") | ||
}, | ||
|
||
Store: func(request http.Request) http.Response { | ||
return http.Json("{\"test Store\": 123}") | ||
}, | ||
|
||
Destroy: func(request http.Request) http.Response { | ||
return http.Json("{\"test Destroy\": 123}") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ type Container interface { | |
|
||
// Register a shared binding in the container. | ||
singleton() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package decorator | ||
|
||
import "lanvard/foundation" | ||
|
||
type BootServiceProvider interface { | ||
Boot(app foundation.Application) foundation.Application | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package decorator | ||
|
||
import "lanvard/foundation" | ||
|
||
type RegisterServiceProvider interface { | ||
Register(app foundation.Application) foundation.Application | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package routing | ||
|
||
func createRoutes(methods []string, uri string, controller ControllerMethod) RouteCollection { | ||
routes := NewRouteCollection() | ||
for _, method := range methods { | ||
route := NewRoute(uri, method, controller) | ||
routes.Push(route) | ||
} | ||
|
||
return routes | ||
} | ||
|
||
func createRoute(method string, uri string, controller ControllerMethod) RouteCollection { | ||
methods := []string{method} | ||
return createRoutes(methods, uri, controller) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package routing | ||
|
||
import ( | ||
"lanvard/http" | ||
net "net/http" | ||
) | ||
|
||
type ControllerMethod func(http.Request) http.Response | ||
|
||
// All of the methods supported by the router. | ||
var allMethods = []string{ | ||
net.MethodGet, | ||
net.MethodHead, | ||
net.MethodPost, | ||
net.MethodPut, | ||
net.MethodPatch, | ||
net.MethodDelete, | ||
net.MethodOptions, | ||
} | ||
|
||
// Register new GET routes | ||
func Get(uri string, controller ControllerMethod) RouteCollection { | ||
methods := []string{net.MethodGet, net.MethodHead} | ||
return createRoutes(methods, uri, controller) | ||
} | ||
|
||
// Register new POST routes | ||
func Post(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoute(net.MethodPost, uri, controller) | ||
} | ||
|
||
// Register new PUT routes | ||
func Put(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoute(net.MethodPut, uri, controller) | ||
} | ||
|
||
// Register new PATCH routes | ||
func Patch(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoute(net.MethodPatch, uri, controller) | ||
} | ||
|
||
// Register new DELETE routes | ||
func Delete(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoute(net.MethodDelete, uri, controller) | ||
} | ||
|
||
// Register new OPTIONS routes | ||
func Options(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoute(net.MethodOptions, uri, controller) | ||
} | ||
|
||
// Register a new route responding to all methods | ||
func Any(uri string, controller ControllerMethod) RouteCollection { | ||
return createRoutes(allMethods, uri, controller) | ||
} |
Oops, something went wrong.