MCPcopy
hub / github.com/purpleidea/mgmt / GetFunctionName

Function GetFunctionName

lang/funcs/funcs.go:245–270  ·  view source on GitHub ↗

GetFunctionName reads the handle to find the underlying real function name. The function can be an actual function or a struct which implements one.

(fn interface{})

Source from the content-addressed store, hash-verified

243// GetFunctionName reads the handle to find the underlying real function name.
244// The function can be an actual function or a struct which implements one.
245func GetFunctionName(fn interface{}) string {
246 pc := runtime.FuncForPC(reflect.ValueOf(fn).Pointer())
247 if pc == nil {
248 // This part works for structs, the other parts work for funcs.
249 t := reflect.TypeOf(fn)
250 if t.Kind() == reflect.Pointer {
251 t = t.Elem()
252 }
253
254 return t.Name()
255 }
256
257 // if pc.Name() is: github.com/purpleidea/mgmt/lang/core/math.Pow
258 sp := strings.Split(pc.Name(), "/")
259
260 // ...this will be: math.Pow
261 s := sp[len(sp)-1]
262
263 ix := strings.LastIndex(s, ".")
264 if ix == -1 { // standalone
265 return s
266 }
267
268 // ... this will be: Pow
269 return s[ix+1:]
270}
271
272// GetFunctionMetadata builds a metadata struct with everything about this func.
273func GetFunctionMetadata(fn interface{}) (*docsUtil.Metadata, error) {

Callers 2

genFunctionsMethod · 0.92
GetFunctionMetadataFunction · 0.85

Calls 2

KindMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected