mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
These two fields are very helpful to generate documentation with swagger. Signed-off-by: David Calavera <david.calavera@gmail.com>
28 lines
400 B
Go
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
|
|
}
|