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

New: gRPC MVC features, new WithLowercaseRouting option and add some new context methods

read HISTORY.md


Former-commit-id: 30a16cceb11f754aa32923058abeda1e736350e7
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-25 02:30:19 +03:00
parent 0cf5d5a4a3
commit 5d3c96947c
21 changed files with 566 additions and 185 deletions

View File

@@ -1,6 +1,7 @@
package context
import (
"path/filepath"
"reflect"
"runtime"
"strings"
@@ -27,20 +28,38 @@ type Handler func(Context)
// See `Handler` for more.
type Handlers []Handler
func valueOf(v interface{}) reflect.Value {
if val, ok := v.(reflect.Value); ok {
return val
}
return reflect.ValueOf(v)
}
// HandlerName returns the handler's function name.
// See `context.HandlerName` to get function name of the current running handler in the chain.
func HandlerName(h Handler) string {
pc := reflect.ValueOf(h).Pointer()
func HandlerName(h interface{}) string {
pc := valueOf(h).Pointer()
return runtime.FuncForPC(pc).Name()
}
// HandlerFileLine returns the handler's file and line information.
// See `context.HandlerFileLine` to get the file, line of the current running handler in the chain.
func HandlerFileLine(h Handler) (file string, line int) {
pc := reflect.ValueOf(h).Pointer()
func HandlerFileLine(h interface{}) (file string, line int) {
pc := valueOf(h).Pointer()
return runtime.FuncForPC(pc).FileLine(pc)
}
// HandlerFileLineRel same as `HandlerFileLine` but it returns the path as relative to the "workingDir".
func HandlerFileLineRel(h interface{}, workingDir string) (string, int) {
file, line := HandlerFileLine(h)
if relFile, err := filepath.Rel(workingDir, file); err == nil {
file = "./" + relFile
}
return file, line
}
// MainHandlerName tries to find the main handler than end-developer
// registered on the provided chain of handlers and returns its function name.
func MainHandlerName(handlers Handlers) (name string) {