mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Rename AddHandlerCtx to AddHandler (#43557)
This commit is contained in:
@@ -37,7 +37,7 @@ type Bus interface {
|
||||
// callback returns an error.
|
||||
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
|
||||
|
||||
AddHandlerCtx(handler HandlerFunc)
|
||||
AddHandler(handler HandlerFunc)
|
||||
|
||||
AddEventListenerCtx(handler HandlerFunc)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
|
||||
if withCtx {
|
||||
params = append(params, reflect.ValueOf(ctx))
|
||||
} else if setting.Env == setting.Dev {
|
||||
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandlerCtx", "msgName", msgName)
|
||||
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandler", "msgName", msgName)
|
||||
}
|
||||
params = append(params, reflect.ValueOf(msg))
|
||||
|
||||
@@ -172,7 +172,7 @@ func callListeners(listeners []HandlerFunc, params []reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *InProcBus) AddHandlerCtx(handler HandlerFunc) {
|
||||
func (b *InProcBus) AddHandler(handler HandlerFunc) {
|
||||
handlerType := reflect.TypeOf(handler)
|
||||
queryTypeName := handlerType.In(1).Elem().Name()
|
||||
b.handlersWithCtx[queryTypeName] = handler
|
||||
@@ -193,10 +193,10 @@ func (b *InProcBus) AddEventListenerCtx(handler HandlerFunc) {
|
||||
b.listenersWithCtx[eventName] = append(b.listenersWithCtx[eventName], handler)
|
||||
}
|
||||
|
||||
// AddHandlerCtx attaches a handler function to the global bus context.
|
||||
// AddHandler attaches a handler function to the global bus context.
|
||||
// Package level function.
|
||||
func AddHandlerCtx(implName string, handler HandlerFunc) {
|
||||
globalBus.AddHandlerCtx(handler)
|
||||
func AddHandler(implName string, handler HandlerFunc) {
|
||||
globalBus.AddHandler(handler)
|
||||
}
|
||||
|
||||
// AddEventListenerCtx attaches a handler function to the event listener.
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestDispatch(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@@ -42,7 +42,7 @@ func TestDispatch_ContextHandler(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@@ -58,7 +58,7 @@ func TestDispatchCtx(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@@ -74,7 +74,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@@ -98,7 +98,7 @@ func TestQuery(t *testing.T) {
|
||||
|
||||
want := "hello from handler"
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, q *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, q *testQuery) error {
|
||||
q.Resp = want
|
||||
return nil
|
||||
})
|
||||
@@ -114,7 +114,7 @@ func TestQuery(t *testing.T) {
|
||||
func TestQuery_HandlerReturnsError(t *testing.T) {
|
||||
bus := New()
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
return errors.New("handler error")
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user