Skip to content

Commit

Permalink
Support nested DSLs by eval.caller()
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed May 28, 2024
1 parent 854598c commit fbfab3b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,26 @@ func finalizeSet(set ExpressionSet) {

// caller returns the name of calling function.
func caller() string {
for skip := 2; skip <= 4; skip++ {
var latest string
for skip := 2; skip <= 5; skip++ {
pc, _, _, ok := runtime.Caller(skip)
if !ok {
break
}
name := runtime.FuncForPC(pc).Name()
elems := strings.Split(name, ".")
caller := elems[len(elems)-1]
if !strings.HasPrefix(name, "goa.design/goa/v3/dsl.") {
break
}
caller := strings.Split(strings.TrimPrefix(name, "goa.design/goa/v3/dsl."), ".")[0]
for _, first := range caller {
if unicode.IsUpper(first) {
return caller
latest = caller
}
break
}
}
if latest != "" {
return latest
}
return "<unknown>"
}

0 comments on commit fbfab3b

Please sign in to comment.