mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 03:01:03 +01:00
29835d9a8e
Former-commit-id: d325be0e953efc2f841c69f62233b34d4a58ab62
51 lines
925 B
Go
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
|
|
}
|