gin/function.go
David Calavera 7010af371d Add File and line location to RouteInfo.
These two fields are very helpful to generate documentation with
swagger.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-09-07 17:02:58 -04:00

28 lines
400 B
Go

package gin
import (
"reflect"
"runtime"
)
type Function struct {
Name string
File string
Line int
}
func parseFunction(f interface{}) Function {
ptr := reflect.ValueOf(f).Pointer()
fu := runtime.FuncForPC(ptr)
file, line := fu.FileLine(ptr)
return Function{
Name: fu.Name(),
File: file,
Line: line,
}
}
func nameOfFunction(f interface{}) string {
return parseFunction(f).Name
}