json/handler.go
func Register(registrar tchannel.Registrar, funcs Handlers, onError func(context.Context, error)) error {
	handlers := make(map[string]*handler)

	handler := tchannel.HandlerFunc(func(ctx context.Context, call *tchannel.InboundCall) {
		h, ok := handlers[string(call.Method())]
		if !ok {
			onError(ctx, fmt.Errorf("call for unregistered method: %s", call.Method()))
			return
		}

		if err := h.Handle(ctx, call); err != nil {
			onError(ctx, err)
		}
	})

	for m, f := range funcs {
		h, err := toHandler(f)
		if err != nil {
			return fmt.Errorf("%v cannot be used as a handler: %v", m, err)
		}
		h.tracer = func() opentracing.Tracer {
			return tchannel.TracerFromRegistrar(registrar)
		}
		handlers[m] = h
		registrar.Register(handler, m)
	}

	return nil
}
func Register(registrar tchannel.Registrar, funcs Handlers, onError func(context.Context, error)) error {
	handlers := make(map[string]*handler)

	handler := tchannel.HandlerFunc(func(ctx context.Context, call *tchannel.InboundCall) {
		h, ok := handlers[string(call.Method())]
		if !ok {
			onError(ctx, fmt.Errorf("call for unregistered method: %s", call.Method()))
			return
		}

		if err := h.Handle(ctx, call); err != nil {
			onError(ctx, err)
		}
	})

	for m, f := range funcs {
		h, err := toHandler(f)
		if err != nil {
			return fmt.Errorf("%v cannot be used as a handler: %v", m, err)
		}
		h.tracer = func() opentracing.Tracer {
			return tchannel.TracerFromRegistrar(registrar)
		}
		handlers[m] = h
		registrar.Register(handler, m)
	}

	return nil
}
// Register registers the specified methods specified as a map from method name to the
// JSON handler function. The handler functions should have the following signature:
// func(context.Context, *ArgType)(*ResType, error)