iris/mvc2/mvc.go
kataras 29835d9a8e black-box the MakeHandler, works perfectly.
Former-commit-id: d325be0e953efc2f841c69f62233b34d4a58ab62
2017-11-24 15:10:30 +02:00

51 lines
925 B
Go

package mvc2
import (
"errors"
"github.com/kataras/iris/context"
)
var (
errNil = errors.New("nil")
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 {
h, _ := MakeHandler(handler, m.binders) // it logs errors already, so on any error the "h" will be nil.
return h
}