2017-11-23 11:43:29 +01:00
|
|
|
package mvc2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-11-24 11:32:35 +01:00
|
|
|
|
|
|
|
"github.com/kataras/iris/context"
|
2017-11-23 11:43:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
errNil = errors.New("nil")
|
|
|
|
errBad = errors.New("bad")
|
|
|
|
errAlreadyExists = errors.New("already exists")
|
|
|
|
)
|
2017-11-24 11:32:35 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|