Skip to content

Commit

Permalink
Merge pull request #12 from Fenny/master
Browse files Browse the repository at this point in the history
Fix FunctionName
  • Loading branch information
Fenny authored Jun 7, 2020
2 parents 31fef6a + b7b3e72 commit b7cbd65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func UUID() string {

// Returns function name
func FunctionName(fn interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
t := reflect.ValueOf(fn).Type()
if t.Kind() == reflect.Func {
return runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
}
return t.String()
}

// ToLower is the equivalent of strings.ToLower
Expand Down
5 changes: 5 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
func Test_Utils_FunctionName(t *testing.T) {
t.Parallel()
AssertEqual(t, "github.com/gofiber/utils.Test_Utils_UUID", FunctionName(Test_Utils_UUID))

AssertEqual(t, "github.com/gofiber/utils.Test_Utils_FunctionName.func1", FunctionName(func() {}))

var dummyint = 20
AssertEqual(t, "int", FunctionName(dummyint))
}

func Test_Utils_UUID(t *testing.T) {
Expand Down

0 comments on commit b7cbd65

Please sign in to comment.