diff --git a/svloc.go b/svloc.go index 3cf766c..d5c1239 100644 --- a/svloc.go +++ b/svloc.go @@ -91,11 +91,13 @@ type registeredService struct { onShutdown func() } -func (s *registeredService) newService(unv *Universe, callLoc string) any { +func (s *registeredService) newService(unv *Universe) any { if s.onceDone.Load() { return s.svc } + callLoc := getCallerLocationWithSkip(2) + svc := s.newServiceSlow(unv, callLoc) unv.data.appendShutdownFunc(s.onShutdown) @@ -255,9 +257,7 @@ func (s *Locator[T]) Get(unv *Universe) T { panic(err.Error()) } - loc := getCallerLocation() - - svc := reg.newService(unv, loc) + svc := reg.newService(unv) result, ok := svc.(T) if !ok { var empty T @@ -451,6 +451,11 @@ func checkAllowRegistering() { } } +func getCallerLocationWithSkip(skip int) string { + _, file, line, _ := runtime.Caller(skip + 1) + return fmt.Sprintf("%s:%d", file, line) +} + func getCallerLocation() string { _, file, line, _ := runtime.Caller(2) return fmt.Sprintf("%s:%d", file, line)