Skip to content
/ funcname Public

funcname is a Go module that provides utility functions for retrieving and manipulating function names.

License

Notifications You must be signed in to change notification settings

goaux/funcname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

funcname

Go Reference Go Report Card

funcname is a Go package that provides utility functions for retrieving and manipulating function names. It offers various methods to obtain function names from different contexts, such as runtime program counters, interface values, and the current call stack.

Installation

To install the funcname package, use the following command:

go get github.com/goaux/funcname

Usage

Here are some examples of how to use the funcname package:

package main

import (
    "fmt"
    "github.com/goaux/funcname"
)

func main() {
    // Get the name of the current function
    fmt.Println(funcname.This())

    // Get the name of a function from an interface
    fmt.Println(funcname.Of(fmt.Println))

    // Split a function name into package and function components
    pkg, fn := funcname.Split("github.com/user/pkg.Func")
    fmt.Printf("Package: %s, Function: %s\n", pkg, fn)
}

API

The funcname package provides the following main functions:

  • Of(v interface{}) string: Returns the full name of the function or method represented by v.
  • SplitOf(v interface{}) (pkgname, name string): Returns the package name and function name of the function or method represented by v.
  • This() string: Returns the name of the calling function.
  • SplitThis() (pkgname, name string): Returns the package name and function name of the calling function.
  • Caller(skip int) string: Returns the name of the calling function, skipping the specified number of stack frames.
  • SplitCaller(skip int) (pkgname, name string): Returns the package name and function name of the calling function, skipping the specified number of stack frames.
  • ForPC(pc uintptr) string: Returns the name of the function corresponding to the given program counter.
  • SplitForPC(pc uintptr) (pkgname, name string): Returns the package name and function name corresponding to the given program counter.
  • Split(s string) (pkgname, name string): Separates a fully qualified function name into package name and function name.

About

funcname is a Go module that provides utility functions for retrieving and manipulating function names.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages