mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 02:47:04 +00:00
implement the makeHandler and structure the high-level mvc's API
Former-commit-id: 412118eae436981711ef57821f2d85b77a5d1a12
This commit is contained in:
38
mvc2/mvc.go
38
mvc2/mvc.go
@@ -2,6 +2,8 @@ package mvc2
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -9,3 +11,39 @@ var (
|
||||
errBad = errors.New("bad")
|
||||
errAlreadyExists = errors.New("already exists")
|
||||
)
|
||||
|
||||
type Mvc struct {
|
||||
binders []*InputBinder
|
||||
}
|
||||
|
||||
func New() *Mvc {
|
||||
return new(Mvc)
|
||||
}
|
||||
|
||||
func (m *Mvc) RegisterBinder(binders ...interface{}) error {
|
||||
for _, binder := range binders {
|
||||
b, err := MakeFuncInputBinder(binder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.binders = append(m.binders, b)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mvc) RegisterService(services ...interface{}) error {
|
||||
for _, service := range services {
|
||||
b, err := MakeServiceInputBinder(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.binders = append(m.binders, b)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mvc) Handler(handler interface{}) context.Handler {
|
||||
return makeHandler(handler, m.binders)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user