Skip to content

Commit

Permalink
Update to version 12.1.8 - Read HISTORY.md
Browse files Browse the repository at this point in the history
Former-commit-id: d3d30cb15537146e3071731be9d674a5cb59de97
  • Loading branch information
kataras committed Feb 16, 2020
1 parent 899aec8 commit 08403f0
Show file tree
Hide file tree
Showing 21 changed files with 275 additions and 240 deletions.
14 changes: 14 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene

**How to upgrade**: Open your command-line and execute this command: `go get github.com/kataras/iris/v12@latest`.

# Su, 16 February 2020 | v12.1.8

New Features:

- [[FEATURE REQUEST] MVC serving gRPC-compatible controller](https://github.com/kataras/iris/issues/1449)

Fixes:

- [App can't find embedded pug template files by go-bindata](https://github.com/kataras/iris/issues/1450)

New Examples:

- [_examples/mvc/grpc-compatible](_examples/mvc/grpc-compatible)

# Mo, 10 February 2020 | v12.1.7

Implement **new** `SetRegisterRule(iris.RouteOverride, RouteSkip, RouteError)` to resolve: https://github.com/kataras/iris/issues/1448
Expand Down
4 changes: 2 additions & 2 deletions HISTORY_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Los desarrolladores no están obligados a actualizar si realmente no lo necesita

**Cómo actualizar**: Abra su línea de comandos y ejecute este comando: `go get github.com/kataras/iris/v12@latest`.

# Mo, 10 February 2020 | v12.1.7
# Su, 16 February 2020 | v12.1.8

Not translated yet, please navigate to the [english version](HISTORY.md#mo-10-february-2020--v1217) instead.
Not translated yet, please navigate to the [english version](HISTORY.md#su-16-february-2020--v1218) instead.

# Sábado, 26 de octubre 2019 | v12.0.0

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!-- # News
# News

![](https://iris-go.com/images/release.png) Iris version **12.1.7** has been [released](HISTORY.md#mo-10-february-2020--v1217)!
![](https://iris-go.com/images/release.png) Iris version **12.1.8** has been [released](HISTORY.md#su-16-february-2020--v1218)!

![](https://iris-go.com/images/cli.png) The official [Iris Command Line Interface](https://github.com/kataras/iris-cli) will soon be near you in 2020!

![](https://iris-go.com/images/sponsor.png) Support your favorite web framework through [Github Sponsors Program](https://github.com/sponsors/kataras)! -->
![](https://iris-go.com/images/sponsor.png) Support your favorite web framework through [Github Sponsors Program](https://github.com/sponsors/kataras)!

# Iris Web Framework <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_KO.md"><img width="20px" src="https://iris-go.com/images/flag-south-korea.svg" /></a> <a href="README_FA.md"><img width="20px" src="https://iris-go.com/images/flag-iran.svg" /></a> <a href="README_RU.md"><img width="20px" src="https://iris-go.com/images/flag-russia.svg" /></a>

[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/kataras/iris) [![FOSSA Status](https://img.shields.io/badge/LICENSE%20SCAN-PASSING❤️-CD2956?style=for-the-badge&logo=fossa)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkataras%2Firis?ref=badge_shield)<!--[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/iris)--><!--[![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://godoc.org/github.com/kataras/iris)--> [![view examples](https://img.shields.io/badge/learn%20by-examples-0C8EC5.svg?style=for-the-badge&logo=go)](https://github.com/kataras/iris/tree/master/_examples) [![chat](https://img.shields.io/gitter/room/iris_go/community.svg?color=7E18DD&logo=gitter&style=for-the-badge)](https://gitter.im/iris_go/community)<!--[![donate on PayPal](https://img.shields.io/badge/support-PayPal-blue.svg?style=for-the-badge)](https://www.paypal.me/kataras)--><!-- [![release](https://img.shields.io/badge/release%20-v12.0-0077b3.svg?style=for-the-badge)](https://github.com/kataras/iris/releases) -->
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.1.7:https://github.com/kataras/iris/releases/tag/v12.1.7
12.1.8:https://github.com/kataras/iris/releases/tag/v12.1.8
2 changes: 1 addition & 1 deletion _examples/docker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module app
go 1.13

require (
github.com/kataras/iris/v12 v12.1.7
github.com/kataras/iris/v12 v12.1.8
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
)
18 changes: 13 additions & 5 deletions _examples/mvc/grpc-compatible/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ func newApp() *iris.Application {
return ctx.Request().Context()
}).
// Bind loginRequest.
Register(func(ctx iris.Context) loginRequest {
var req loginRequest
ctx.ReadJSON(&req)
return req
}).
// Register(func(ctx iris.Context) loginRequest {
// var req loginRequest
// ctx.ReadJSON(&req)
// return req
// }).
// OR
// Bind any other structure or pointer to a structure from request's
// XML
// YAML
// Query
// Form
// JSON (default, if not client's "Content-Type" specified otherwise)
Register(mvc.AutoBinding).
Handle(&myController{})

return app
Expand Down
2 changes: 1 addition & 1 deletion _examples/mvc/grpc-compatible/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/kataras/iris/v12/httptest"
)

func TestBindContextContext(t *testing.T) {
func TestGRPCCompatible(t *testing.T) {
app := newApp()

e := httptest.New(t, app)
Expand Down
6 changes: 3 additions & 3 deletions _examples/view/template_pug_3/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Source code and other details for the project are available at GitHub:
Current Version
12.1.7
12.1.8
Installation
Expand Down
43 changes: 0 additions & 43 deletions hero/di.go

This file was deleted.

135 changes: 85 additions & 50 deletions hero/di/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
)

type (
// Hijacker is a type which is used to catch fields or function's input argument
// to bind a custom object based on their type.
Hijacker func(reflect.Type) (*BindObject, bool)
// TypeChecker checks if a specific field's or function input argument's
// is valid to be binded.
TypeChecker func(reflect.Type) bool
// ErrorHandler is the optional interface to handle errors per hero func,
// see `mvc/Application#HandleError` for MVC application-level error handler registration too.
//
Expand All @@ -34,15 +28,51 @@ func (fn ErrorHandlerFunc) HandleError(ctx context.Context, err error) {
fn(ctx, err)
}

var (
// DefaultHijacker is the hijacker used on the package-level Struct & Func functions.
DefaultHijacker Hijacker
// DefaultTypeChecker is the typechecker used on the package-level Struct & Func functions.
DefaultTypeChecker TypeChecker
// DefaultErrorHandler is the error handler used on the package-level `Func` function
// to catch any errors from dependencies or handlers.
DefaultErrorHandler ErrorHandler
)
// DefaultErrorHandler is the default error handler will be fired on
// any error from registering a request-scoped dynamic dependency and on a controller's method failure.
var DefaultErrorHandler ErrorHandler = ErrorHandlerFunc(func(ctx context.Context, err error) {
if err == nil {
return
}

ctx.StatusCode(400)
ctx.WriteString(err.Error())
ctx.StopExecution()
})

var emptyValue reflect.Value

// DefaultFallbackBinder used to bind any oprhan inputs. Its error is handled by the `ErrorHandler`.
var DefaultFallbackBinder FallbackBinder = func(ctx context.Context, input OrphanInput) (newValue reflect.Value, err error) {
wasPtr := input.Type.Kind() == reflect.Ptr

newValue = reflect.New(IndirectType(input.Type))
ptr := newValue.Interface()

switch ctx.GetContentTypeRequested() {
case context.ContentXMLHeaderValue:
err = ctx.ReadXML(ptr)
case context.ContentYAMLHeaderValue:
err = ctx.ReadYAML(ptr)
case context.ContentFormHeaderValue:
err = ctx.ReadQuery(ptr)
case context.ContentFormMultipartHeaderValue:
err = ctx.ReadForm(ptr)
default:
err = ctx.ReadJSON(ptr)
// json
}

// if err != nil {
// return emptyValue, err
// }

if !wasPtr {
newValue = newValue.Elem()
}

return newValue, err
}

// Struct is being used to return a new injector based on
// a struct value instance, if it contains fields that the types of those
Expand All @@ -55,8 +85,6 @@ func Struct(s interface{}, values ...reflect.Value) *StructInjector {

return MakeStructInjector(
ValueOf(s),
DefaultHijacker,
DefaultTypeChecker,
SortByNumMethods,
Values(values).CloneWithFieldsOf(s)...,
)
Expand All @@ -74,9 +102,6 @@ func Func(fn interface{}, values ...reflect.Value) *FuncInjector {

return MakeFuncInjector(
ValueOf(fn),
DefaultHijacker,
DefaultTypeChecker,
DefaultErrorHandler,
values...,
)
}
Expand All @@ -88,28 +113,34 @@ func Func(fn interface{}, values ...reflect.Value) *FuncInjector {
type D struct {
Values

hijacker Hijacker
goodFunc TypeChecker
errorHandler ErrorHandler
sorter Sorter
fallbackBinder FallbackBinder
errorHandler ErrorHandler
sorter Sorter
}

// OrphanInput represents an input without registered dependency.
// Used to help the framework (or the caller) auto-resolve it by the request.
type OrphanInput struct {
// Index int // function or struct field index.
Type reflect.Type
}

// FallbackBinder represents a handler of oprhan input values, handler's input arguments or controller's fields.
type FallbackBinder func(ctx context.Context, input OrphanInput) (reflect.Value, error)

// New creates and returns a new Dependency Injection container.
// See `Values` field and `Func` and `Struct` methods for more.
func New() *D {
return &D{}
}

// Hijack sets a hijacker function, read the `Hijacker` type for more explanation.
func (d *D) Hijack(fn Hijacker) *D {
d.hijacker = fn
return d
return &D{
errorHandler: DefaultErrorHandler,
fallbackBinder: DefaultFallbackBinder,
}
}

// GoodFunc sets a type checker for a valid function that can be binded,
// read the `TypeChecker` type for more explanation.
func (d *D) GoodFunc(fn TypeChecker) *D {
d.goodFunc = fn
// FallbackBinder adds a binder which will handle any oprhan input values.
// See `FallbackBinder` type.
func (d *D) FallbackBinder(fallbackBinder FallbackBinder) *D {
d.fallbackBinder = fallbackBinder
return d
}

Expand All @@ -130,11 +161,10 @@ func (d *D) Sort(with Sorter) *D {
// parent's (current "D") hijacker, good func type checker, sorter and all dependencies values.
func (d *D) Clone() *D {
return &D{
Values: d.Values.Clone(),
hijacker: d.hijacker,
goodFunc: d.goodFunc,
errorHandler: d.errorHandler,
sorter: d.sorter,
Values: d.Values.Clone(),
fallbackBinder: d.fallbackBinder,
errorHandler: d.errorHandler,
sorter: d.sorter,
}
}

Expand All @@ -144,16 +174,19 @@ func (d *D) Clone() *D {
// with the injector's `Inject` and `InjectElem` methods.
func (d *D) Struct(s interface{}) *StructInjector {
if s == nil {
return &StructInjector{Has: false}
return &StructInjector{}
}

return MakeStructInjector(
injector := MakeStructInjector(
ValueOf(s),
d.hijacker,
d.goodFunc,
d.sorter,
d.Values.CloneWithFieldsOf(s)...,
)

injector.ErrorHandler = d.errorHandler
injector.FallbackBinder = d.fallbackBinder

return injector
}

// Func is being used to return a new injector based on
Expand All @@ -163,14 +196,16 @@ func (d *D) Struct(s interface{}) *StructInjector {
// with the injector's `Inject` method.
func (d *D) Func(fn interface{}) *FuncInjector {
if fn == nil {
return &FuncInjector{Has: false}
return &FuncInjector{}
}

return MakeFuncInjector(
injector := MakeFuncInjector(
ValueOf(fn),
d.hijacker,
d.goodFunc,
d.errorHandler,
d.Values...,
).ErrorHandler(d.errorHandler)
)

injector.ErrorHandler = d.errorHandler
injector.FallbackBinder = d.fallbackBinder

return injector
}
Loading

0 comments on commit 08403f0

Please sign in to comment.