package eventadapter import ( "fmt" "runtime" "strings" ) type ( ctxKey string ) // SubscriptionID returns a unique ID for the given topic and subscriber ID. It is what we // name the subscriptions in Google. func SubscriptionID(topicName, subscriberID string) string { return fmt.Sprintf("%s---%s", topicName, subscriberID) } // getCallerPackageName returns the package name of the caller of the function that called // our caller. func getCallerPackageName() string { for back := 0; back < 10; back++ { pc, _, _, _ := runtime.Caller(back) // e.g. "github.com/incident-io/core/server/app/escalator/executor.(*Executor).Run" packageName := runtime.FuncForPC(pc).Name() // Check we're in our own code. if !strings.Contains(packageName, "github.com/incident-io/core/server/") { continue } // e.g. "app/escalator/executor.(*Executor).Run" packageName = strings.TrimPrefix(packageName, "github.com/incident-io/core/server/") // e.g. "app/escalator/executor" packageName = strings.Split(packageName, ".")[0] if strings.HasPrefix(packageName, "lib/database") || strings.HasPrefix(packageName, "pkg/event/eventadapter") { continue } return packageName } return "unknown" }