21 lines
459 B
Go
21 lines
459 B
Go
package parse
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func callerFilepos(depth int) string {
|
|
// No error handling, because we call this method ourselves with safe depth values.
|
|
_, file, line, _ := runtime.Caller(depth + 1)
|
|
return fmt.Sprintf("%s:%d", file, line)
|
|
}
|
|
|
|
func callerPanic(depth int, f string, args ...interface{}) {
|
|
filepos := callerFilepos(depth + 1)
|
|
m := fmt.Sprintf(f, args...)
|
|
m = strings.Replace(m, "{caller}", filepos, 1)
|
|
panic(m)
|
|
}
|