Esempio n. 1
0
func (r staticRegistry) GetHandlerSpec(service string, procedure string) (transport.HandlerSpec, error) {
	if procedure == testProcedure {
		return transport.NewUnaryHandlerSpec(r.Handler), nil
	} else {
		return transport.NewOnewayHandlerSpec(r.OnewayHandler), nil
	}
}
Esempio n. 2
0
// OnewayProcedure builds a Registrant from the given raw handler
func OnewayProcedure(name string, handler OnewayHandler) []transport.Registrant {
	return []transport.Registrant{
		{
			Procedure:   name,
			HandlerSpec: transport.NewOnewayHandlerSpec(rawOnewayHandler{handler}),
		},
	}
}
Esempio n. 3
0
// OnewayProcedure builds a Registrant from the given JSON handler. handler must be
// a function with a signature similar to,
//
// 	f(ctx context.Context, reqMeta yarpc.ReqMeta, body $reqBody) error
//
// Where $reqBody is a map[string]interface{} or pointer to a struct.
func OnewayProcedure(name string, handler interface{}) []transport.Registrant {
	return []transport.Registrant{
		{
			Procedure: name,
			HandlerSpec: transport.NewOnewayHandlerSpec(
				wrapOnewayHandler(name, handler)),
		},
	}
}
Esempio n. 4
0
// BuildRegistrants builds a list of Registrants from a Thrift service
// specification.
func BuildRegistrants(s Service, opts ...RegisterOption) []transport.Registrant {
	var rc registerConfig
	for _, opt := range opts {
		opt.applyRegisterOption(&rc)
	}

	proto := protocol.Binary
	if rc.Protocol != nil {
		proto = rc.Protocol
	}

	rs := make([]transport.Registrant, 0, len(s.Methods))

	// unary procedures
	for methodName, handler := range s.Methods {
		spec := transport.NewUnaryHandlerSpec(thriftUnaryHandler{
			UnaryHandler: handler,
			Protocol:     proto,
			Enveloping:   rc.Enveloping,
		})

		rs = append(rs, transport.Registrant{
			Procedure:   procedureName(s.Name, methodName),
			HandlerSpec: spec,
		})
	}

	// oneway procedures
	for methodName, handler := range s.OnewayMethods {
		spec := transport.NewOnewayHandlerSpec(thriftOnewayHandler{
			OnewayHandler: handler,
			Protocol:      proto,
			Enveloping:    rc.Enveloping,
		})

		rs = append(rs, transport.Registrant{
			Procedure:   procedureName(s.Name, methodName),
			HandlerSpec: spec,
		})
	}

	return rs
}