forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to Version 8.4.2 | Read HISTORY.md
- Loading branch information
Showing
14 changed files
with
382 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8.4.1:https://github.com/kataras/iris/blob/master/HISTORY.md#th-07-september-2017--v841 | ||
8.4.2:https://github.com/kataras/iris/blob/master/HISTORY.md#fr-15-september-2017--v842 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,62 @@ | ||
package methodfunc | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/kataras/iris/context" | ||
) | ||
|
||
// FuncCaller is responsible to call the controller's function | ||
// which is responsible | ||
// for that request for this http method. | ||
type FuncCaller interface { | ||
// MethodCall fires the actual handler. | ||
// The "ctx" is the current context, helps us to get any path parameter's values. | ||
// | ||
// The "f" is the controller's function which is responsible | ||
// for that request for this http method. | ||
// That function can accept one parameter. | ||
// | ||
// The default callers (and the only one for now) | ||
// are pre-calculated by the framework. | ||
MethodCall(ctx context.Context, f interface{}) | ||
} | ||
|
||
type callerFunc func(ctx context.Context, f interface{}) | ||
// buildMethodCall builds the method caller. | ||
// We have repeated code here but it's the only way | ||
// to support more than one input arguments without performance cost compared to previous implementation. | ||
// so it's hard-coded written to check the length of input args and their types. | ||
func buildMethodCall(a *ast) func(ctx context.Context, f reflect.Value) { | ||
// if accepts one or more parameters. | ||
if a.dynamic { | ||
// if one function input argument then call the function | ||
// by "casting" (faster). | ||
if l := len(a.paramKeys); l == 1 { | ||
paramType := a.paramTypes[0] | ||
paramKey := a.paramKeys[0] | ||
|
||
if paramType == paramTypeInt { | ||
return func(ctx context.Context, f reflect.Value) { | ||
v, _ := ctx.Params().GetInt(paramKey) | ||
f.Interface().(func(int))(v) | ||
} | ||
} | ||
|
||
if paramType == paramTypeLong { | ||
return func(ctx context.Context, f reflect.Value) { | ||
v, _ := ctx.Params().GetInt64(paramKey) | ||
f.Interface().(func(int64))(v) | ||
} | ||
|
||
} | ||
|
||
if paramType == paramTypeBoolean { | ||
return func(ctx context.Context, f reflect.Value) { | ||
v, _ := ctx.Params().GetBool(paramKey) | ||
f.Interface().(func(bool))(v) | ||
} | ||
} | ||
|
||
// string, path... | ||
return func(ctx context.Context, f reflect.Value) { | ||
f.Interface().(func(string))(ctx.Params().Get(paramKey)) | ||
} | ||
|
||
func (c callerFunc) MethodCall(ctx context.Context, f interface{}) { | ||
c(ctx, f) | ||
} | ||
|
||
func resolveCaller(p pathInfo) callerFunc { | ||
// if it's standard `Get`, `Post` without parameters. | ||
if p.ParamType == "" { | ||
return func(ctx context.Context, f interface{}) { | ||
f.(func())() | ||
} | ||
} | ||
|
||
// remember, | ||
// the router already checks for the correct type, | ||
// we did pre-calculate everything | ||
// and now we will pre-calculate the method caller itself as well. | ||
|
||
if p.ParamType == paramTypeInt { | ||
return func(ctx context.Context, f interface{}) { | ||
paramValue, _ := ctx.Params().GetInt(paramName) | ||
f.(func(int))(paramValue) | ||
} | ||
} | ||
|
||
if p.ParamType == paramTypeLong { | ||
return func(ctx context.Context, f interface{}) { | ||
paramValue, _ := ctx.Params().GetInt64(paramName) | ||
f.(func(int64))(paramValue) | ||
} | ||
} | ||
|
||
if p.ParamType == paramTypeBoolean { | ||
return func(ctx context.Context, f interface{}) { | ||
paramValue, _ := ctx.Params().GetBool(paramName) | ||
f.(func(bool))(paramValue) | ||
// if func input arguments are more than one then | ||
// use the Call method (slower). | ||
return func(ctx context.Context, f reflect.Value) { | ||
f.Call(a.paramValues(ctx)) | ||
} | ||
} | ||
|
||
// else it's string or path, both of them are simple strings. | ||
return func(ctx context.Context, f interface{}) { | ||
paramValue := ctx.Params().Get(paramName) | ||
f.(func(string))(paramValue) | ||
// if it's static without any receivers then just call it. | ||
return func(ctx context.Context, f reflect.Value) { | ||
f.Interface().(func())() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package methodfunc | ||
|
||
import ( | ||
"unicode" | ||
) | ||
|
||
const ( | ||
tokenBy = "By" | ||
tokenWildcard = "Wildcard" // should be followed by "By", | ||
) | ||
|
||
// word lexer, not characters. | ||
type lexer struct { | ||
words []string | ||
cur int | ||
} | ||
|
||
func newLexer(s string) *lexer { | ||
l := new(lexer) | ||
l.reset(s) | ||
return l | ||
} | ||
|
||
func (l *lexer) reset(trailing string) { | ||
l.cur = -1 | ||
var words []string | ||
if trailing != "" { | ||
end := len(trailing) | ||
start := -1 | ||
|
||
for i, n := 0, end; i < n; i++ { | ||
c := rune(trailing[i]) | ||
if unicode.IsUpper(c) { | ||
// it doesn't count the last uppercase | ||
if start != -1 { | ||
end = i | ||
words = append(words, trailing[start:end]) | ||
} | ||
start = i | ||
continue | ||
} | ||
end = i + 1 | ||
} | ||
|
||
if end > 0 && len(trailing) >= end { | ||
words = append(words, trailing[start:end]) | ||
} | ||
} | ||
|
||
l.words = words | ||
} | ||
|
||
func (l *lexer) next() (w string) { | ||
cur := l.cur + 1 | ||
|
||
if w = l.peek(cur); w != "" { | ||
l.cur++ | ||
} | ||
|
||
return | ||
} | ||
|
||
func (l *lexer) skip() { | ||
if cur := l.cur + 1; cur < len(l.words) { | ||
l.cur = cur | ||
} else { | ||
l.cur = len(l.words) - 1 | ||
} | ||
} | ||
|
||
func (l *lexer) peek(idx int) string { | ||
if idx < len(l.words) { | ||
return l.words[idx] | ||
} | ||
return "" | ||
} | ||
|
||
func (l *lexer) peekNext() (w string) { | ||
return l.peek(l.cur + 1) | ||
} | ||
|
||
func (l *lexer) peekPrev() (w string) { | ||
if l.cur > 0 { | ||
cur := l.cur - 1 | ||
w = l.words[cur] | ||
} | ||
|
||
return w | ||
} |
Oops, something went wrong.