MCPcopy Index your code
hub / github.com/micro/go-micro / extractSourceFilePath

Function extractSourceFilePath

logger/debug_handler.go:138–162  ·  view source on GitHub ↗

extractSourceFilePath extracts the package/file:line from a PC

(pc uintptr)

Source from the content-addressed store, hash-verified

136
137// extractSourceFilePath extracts the package/file:line from a PC
138func extractSourceFilePath(pc uintptr) string {
139 if pc == 0 {
140 return ""
141 }
142
143 fs := runtime.CallersFrames([]uintptr{pc})
144 f, _ := fs.Next()
145 if f.File == "" {
146 return ""
147 }
148
149 // Extract just filename, not full path
150 idx := strings.LastIndexByte(f.File, '/')
151 if idx == -1 {
152 return fmt.Sprintf("%s:%d", f.File, f.Line)
153 }
154
155 // Get package/file:line
156 idx2 := strings.LastIndexByte(f.File[:idx], '/')
157 if idx2 == -1 {
158 return fmt.Sprintf("%s:%d", f.File[idx+1:], f.Line)
159 }
160
161 return fmt.Sprintf("%s:%d", f.File[idx2+1:], f.Line)
162}

Callers 1

HandleMethod · 0.85

Calls 1

NextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…