MCPcopy
hub / github.com/gin-gonic/gin / function

Function function

recovery.go:172–194  ·  view source on GitHub ↗

function returns, if possible, the name of the function containing the PC.

(pc uintptr)

Source from the content-addressed store, hash-verified

170
171// function returns, if possible, the name of the function containing the PC.
172func function(pc uintptr) string {
173 fn := runtime.FuncForPC(pc)
174 if fn == nil {
175 return dunno
176 }
177 name := fn.Name()
178 // The name includes the path name to the package, which is unnecessary
179 // since the file name is already included. Plus, it has center dots.
180 // That is, we see
181 // runtime/debug.*T·ptrmethod
182 // and want
183 // *T.ptrmethod
184 // Also the package path might contain dot (e.g. code.google.com/...),
185 // so first eliminate the path prefix
186 if lastSlash := strings.LastIndexByte(name, '/'); lastSlash >= 0 {
187 name = name[lastSlash+1:]
188 }
189 if period := strings.IndexByte(name, '.'); period >= 0 {
190 name = name[period+1:]
191 }
192 name = strings.ReplaceAll(name, "·", ".")
193 return name
194}
195
196// timeFormat returns a customized time string for logger.
197func timeFormat(t time.Time) string {

Callers 2

TestFunctionFunction · 0.85
stackFunction · 0.85

Calls 1

NameMethod · 0.65

Tested by 1

TestFunctionFunction · 0.68