1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +00:00

add database/orm/reform example

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-01 03:46:51 +03:00
parent eacbcea653
commit acf058b006
10 changed files with 339 additions and 2 deletions

View File

@@ -3,12 +3,15 @@ package hero
import (
stdContext "context"
"errors"
"net"
"net/http"
"reflect"
"time"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/sessions"
"github.com/kataras/golog"
)
// Default is the default container value which can be used for dependencies share.
@@ -57,6 +60,10 @@ var BuiltinDependencies = []*Dependency{
return session
}).Explicitly(),
// application's logger.
NewDependency(func(ctx *context.Context) *golog.Logger {
return ctx.Application().Logger()
}).Explicitly(),
// time.Time to time.Now dependency.
NewDependency(func(ctx *context.Context) time.Time {
return time.Now()
@@ -73,6 +80,10 @@ var BuiltinDependencies = []*Dependency{
NewDependency(func(ctx *context.Context) http.Header {
return ctx.Request().Header
}).Explicitly(),
// Client IP.
NewDependency(func(ctx *context.Context) net.IP {
return net.ParseIP(ctx.RemoteAddr())
}).Explicitly(),
// payload and param bindings are dynamically allocated and declared at the end of the `binding` source file.
}

View File

@@ -1,6 +1,7 @@
package hero
import (
"net"
"reflect"
"github.com/kataras/iris/v12/context"
@@ -41,9 +42,12 @@ func isFunc(kindable interface{ Kind() reflect.Kind }) bool {
return kindable.Kind() == reflect.Func
}
var inputTyp = reflect.TypeOf((*Input)(nil))
var (
inputTyp = reflect.TypeOf((*Input)(nil))
errTyp = reflect.TypeOf((*error)(nil)).Elem()
var errTyp = reflect.TypeOf((*error)(nil)).Elem()
ipTyp = reflect.TypeOf(net.IP{})
)
// isError returns true if "typ" is type of `error`.
func isError(typ reflect.Type) bool {
@@ -221,6 +225,10 @@ func isZero(v reflect.Value) bool {
return false
}
if v.Type() == ipTyp {
return len(v.Interface().(net.IP)) == 0
}
zero := reflect.Zero(v.Type())
return v.Interface() == zero.Interface()
}