コード例 #1
0
ファイル: roundtrip_test.go プロジェクト: yarpc/yarpc-go
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
	}
}
コード例 #2
0
ファイル: register.go プロジェクト: yarpc/yarpc-go
// 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}),
		},
	}
}
コード例 #3
0
ファイル: register.go プロジェクト: yarpc/yarpc-go
// 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)),
		},
	}
}
コード例 #4
0
ファイル: register.go プロジェクト: yarpc/yarpc-go
// 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
}