반응형
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
- TiDB
- Programming
- UNIX Internals
- 포인터변수
- 긴옵션
- 포인터
- getopts
- 한빛미디어
- 구조와 원리
- UNIX
- Pointer
- bash
- 커널
- Preprocessor
- 전처리기
- DBMS
- 컴퓨터 강좌
- TiKV
- 약어
- DBMS 개발
- SQLite
- 함수포인터
- OS 커널
- Symbol
- FreeBSD
- Golang
- kernel
- go
- Windows via c/c++
- newSQL
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()
}
반응형