caller.go 391 B

123456789101112131415161718192021222324252627282930
  1. package caller
  2. import "runtime"
  3. func CallFilePath() string {
  4. _, file, _, ok := runtime.Caller(1)
  5. if !ok {
  6. return "Unknown"
  7. }
  8. return file
  9. }
  10. func CallFunctionName() string {
  11. pc, _, _, ok := runtime.Caller(1)
  12. if !ok {
  13. return "Unknown"
  14. }
  15. return runtime.FuncForPC(pc).Name()
  16. }
  17. func CallLineNo() int {
  18. _, _, line, ok := runtime.Caller(1)
  19. if !ok {
  20. return 0
  21. }
  22. return line
  23. }