mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
add simple tests for _examples/mvc/hello-world and session-controller
Former-commit-id: d88a792ba57cd869d2888f41bca6eb3e5b4f7d49
This commit is contained in:
@@ -58,8 +58,6 @@ func getNameOf(typ reflect.Type) string {
|
||||
return fullname
|
||||
}
|
||||
|
||||
/// TODO: activate controllers with go routines so the startup time of iris
|
||||
// can be improved on huge applications.
|
||||
func newControllerActivator(router router.Party, controller interface{}, d *di.D) *ControllerActivator {
|
||||
var (
|
||||
val = reflect.ValueOf(controller)
|
||||
@@ -121,24 +119,30 @@ func (c *ControllerActivator) isReservedMethod(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *ControllerActivator) parseMethod(m reflect.Method) {
|
||||
httpMethod, httpPath, err := parseMethod(m, c.isReservedMethod)
|
||||
if err != nil {
|
||||
if err != errSkip {
|
||||
err = fmt.Errorf("MVC: fail to parse the route path and HTTP method for '%s.%s': %v", c.FullName, m.Name, err)
|
||||
c.Router.GetReporter().AddErr(err)
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
c.Handle(httpMethod, httpPath, m.Name)
|
||||
}
|
||||
|
||||
// register all available, exported methods to handlers if possible.
|
||||
func (c *ControllerActivator) parseMethods() {
|
||||
n := c.Type.NumMethod()
|
||||
// wg := &sync.WaitGroup{}
|
||||
// wg.Add(n)
|
||||
for i := 0; i < n; i++ {
|
||||
m := c.Type.Method(i)
|
||||
|
||||
httpMethod, httpPath, err := parseMethod(m, c.isReservedMethod)
|
||||
if err != nil {
|
||||
if err != errSkip {
|
||||
err = fmt.Errorf("MVC: fail to parse the route path and HTTP method for '%s.%s': %v", c.FullName, m.Name, err)
|
||||
c.Router.GetReporter().AddErr(err)
|
||||
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
c.Handle(httpMethod, httpPath, m.Name)
|
||||
c.parseMethod(m)
|
||||
}
|
||||
// wg.Wait()
|
||||
}
|
||||
|
||||
func (c *ControllerActivator) activate() {
|
||||
@@ -248,7 +252,7 @@ func buildHandler(m reflect.Method, typ reflect.Type, initRef reflect.Value, str
|
||||
elemTyp = di.IndirectType(typ)
|
||||
)
|
||||
|
||||
// if it doesn't implements the base controller,
|
||||
// if it doesn't implement the base controller,
|
||||
// it may have struct injector and/or func injector.
|
||||
if !implementsBase {
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ import (
|
||||
"github.com/kataras/iris/mvc"
|
||||
)
|
||||
|
||||
// TODO: It's not here but this file is what I'll see before the commit in order to delete it:
|
||||
// Think a way to simplify the router cycle, I did create it to support any type of router
|
||||
// but as I see nobody wants to override the iris router's behavior(I'm not speaking about wrapper, this will stay of course because it's useful on security-critical middlewares) because it's the best by far.
|
||||
// Therefore I should reduce some "freedom of change" for the shake of code maintanability in the core/router files: handler.go | router.go and single change on APIBuilder's field.
|
||||
func main() {
|
||||
app := iris.New()
|
||||
mvc.New(app.Party("/todo")).Configure(TodoApp)
|
||||
|
||||
Reference in New Issue
Block a user