반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- newSQL
- TiKV
- DBMS 개발
- 함수포인터
- 컴퓨터 강좌
- kernel
- 한빛미디어
- Golang
- Programming
- UNIX Internals
- go
- 구조와 원리
- Preprocessor
- DBMS
- 커널
- 긴옵션
- 전처리기
- 포인터
- TiDB
- Windows via c/c++
- Pointer
- Symbol
- SQLite
- FreeBSD
- bash
- 포인터변수
- OS 커널
- UNIX
- 약어
- getopts
Archives
- Today
- Total
sonumb
Go - 현재 함수 이름 받아오기 본문
출처: https://stackoverflow.com/questions/25927660/how-to-get-the-current-function-name
How to get the current function name
For tracing purpose, I'd like to print out current function name, like the __FUNCTION__ macro in gcc. So that when I have a function func foo () { trace() } it will automatically print out En...
stackoverflow.com
// 반환: 파일이름, 현재라인, 함수이름
func trace() (string, int, string, error) {
pc, file, line, ok := runtime.Caller(1)
if ok == false {
return "?", 0, "?"
}
fn := runtime.FuncForPC(pc)
if fn == nil {
return file, line, "?"
}
return file, line, fn.Name()
}반응형