1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-06 11:37:06 +00:00

👔 next version: some linting

Former-commit-id: a102fbb90e2a8a8b09fcb9c9e0c370e4078b74d1
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-03-01 08:34:53 +02:00
parent 2756435446
commit 1c9b592088
9 changed files with 82 additions and 107 deletions

View File

@@ -2,17 +2,12 @@ package hero
import (
stdContext "context"
"fmt"
"time"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/sessions"
)
func fatalf(format string, args ...interface{}) {
panic(fmt.Sprintf(format, args...))
}
// Default is the default container value which can be used for dependencies share.
var Default = New()
@@ -40,13 +35,15 @@ type Container struct {
GetErrorHandler func(context.Context) ErrorHandler // cannot be nil.
}
// BuiltinDependencies is a list of builtin dependencies that are added on Container's initilization.
// Contains the iris context, standard context, iris sessions and time dependencies.
var BuiltinDependencies = []*Dependency{
// iris context dependency.
NewDependency(func(ctx context.Context) context.Context { return ctx }),
NewDependency(func(ctx context.Context) context.Context { return ctx }).Explicitly(),
// standard context dependency.
NewDependency(func(ctx context.Context) stdContext.Context {
return ctx.Request().Context()
}),
}).Explicitly(),
// iris session dependency.
NewDependency(func(ctx context.Context) *sessions.Session {
session := sessions.Get(ctx)
@@ -55,11 +52,11 @@ var BuiltinDependencies = []*Dependency{
}
return session
}),
}).Explicitly(),
// time.Time to time.Now dependency.
NewDependency(func(ctx context.Context) time.Time {
return time.Now()
}),
}).Explicitly(),
// payload and param bindings are dynamically allocated and declared at the end of the `binding` source file.
}
@@ -161,6 +158,9 @@ func (c *Container) Handler(fn interface{}) context.Handler {
return makeHandler(fn, c)
}
// Struct accepts a pointer to a struct value and returns a structure which
// contains bindings for the struct's fields and a method to
// extract a Handler from this struct's method.
func (c *Container) Struct(ptrValue interface{}) *Struct {
return makeStruct(ptrValue, c)
}