createSubscription will call the subscription callback and returns the subscription id or error.
(ctx context.Context, c ServerCodec, req *serverRequest)
| 242 | |
| 243 | // createSubscription will call the subscription callback and returns the subscription id or error. |
| 244 | func (s *Server) createSubscription(ctx context.Context, c ServerCodec, req *serverRequest) (ID, error) { |
| 245 | // subscription have as first argument the context following optional arguments |
| 246 | args := []reflect.Value{req.callb.rcvr, reflect.ValueOf(ctx)} |
| 247 | args = append(args, req.args...) |
| 248 | reply := req.callb.method.Func.Call(args) |
| 249 | |
| 250 | if !reply[1].IsNil() { // subscription creation failed |
| 251 | return "", reply[1].Interface().(error) |
| 252 | } |
| 253 | |
| 254 | return reply[0].Interface().(*Subscription).ID, nil |
| 255 | } |
| 256 | |
| 257 | // handle executes a request and returns the response from the callback. |
| 258 | func (s *Server) handle(ctx context.Context, codec ServerCodec, req *serverRequest) (interface{}, func()) { |