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