2015-06-03 03:25:37 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-11-20 19:17:33 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
2015-06-03 03:25:37 +03:00
|
|
|
)
|
|
|
|
|
2015-12-01 21:41:43 +03:00
|
|
|
// Handler interface represents a Service request handler. It's generated
|
|
|
|
// by passing any type of public concrete object with methods into server.NewHandler.
|
|
|
|
// Most will pass in a struct.
|
2015-12-01 21:45:52 +03:00
|
|
|
//
|
2015-12-01 21:41:43 +03:00
|
|
|
// Example:
|
2015-12-01 21:45:52 +03:00
|
|
|
//
|
|
|
|
// type Service struct {}
|
|
|
|
//
|
|
|
|
// func (s *Service) Method(context, request, response) error {
|
|
|
|
// return nil
|
|
|
|
// }
|
2015-12-01 21:41:43 +03:00
|
|
|
//
|
2015-06-03 03:25:37 +03:00
|
|
|
type Handler interface {
|
|
|
|
Name() string
|
|
|
|
Handler() interface{}
|
|
|
|
Endpoints() []*registry.Endpoint
|
2016-01-08 17:02:32 +03:00
|
|
|
Options() HandlerOptions
|
2015-06-03 03:25:37 +03:00
|
|
|
}
|
2015-06-12 21:52:27 +03:00
|
|
|
|
2015-12-01 21:41:43 +03:00
|
|
|
// Subscriber interface represents a subscription to a given topic using
|
|
|
|
// a specific subscriber function or object with methods.
|
2015-06-12 21:52:27 +03:00
|
|
|
type Subscriber interface {
|
|
|
|
Topic() string
|
|
|
|
Subscriber() interface{}
|
|
|
|
Endpoints() []*registry.Endpoint
|
2016-01-08 17:02:32 +03:00
|
|
|
Options() SubscriberOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
type HandlerOptions struct {
|
|
|
|
Internal bool
|
2016-05-26 20:01:02 +03:00
|
|
|
Metadata map[string]map[string]string
|
2016-01-08 17:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type SubscriberOptions struct {
|
2016-01-23 00:48:43 +03:00
|
|
|
Queue string
|
2016-01-08 17:02:32 +03:00
|
|
|
Internal bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Internal Handler options specifies that a handler is not advertised
|
|
|
|
// to the discovery system. In the future this may also limit request
|
|
|
|
// to the internal network or authorised user.
|
|
|
|
func InternalHandler(b bool) HandlerOption {
|
|
|
|
return func(o *HandlerOptions) {
|
|
|
|
o.Internal = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 20:01:02 +03:00
|
|
|
// EndpointMetadata is a Handler option that allows metadata to be added to
|
|
|
|
// individual endpoints.
|
2016-05-26 22:25:00 +03:00
|
|
|
func EndpointMetadata(name string, md map[string]string) HandlerOption {
|
2016-05-26 20:01:02 +03:00
|
|
|
return func(o *HandlerOptions) {
|
2016-05-26 22:25:00 +03:00
|
|
|
o.Metadata[name] = md
|
2016-05-26 20:01:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 17:02:32 +03:00
|
|
|
// Internal Subscriber options specifies that a subscriber is not advertised
|
|
|
|
// to the discovery system.
|
|
|
|
func InternalSubscriber(b bool) SubscriberOption {
|
|
|
|
return func(o *SubscriberOptions) {
|
|
|
|
o.Internal = b
|
|
|
|
}
|
2015-06-12 21:52:27 +03:00
|
|
|
}
|
2016-01-23 00:48:43 +03:00
|
|
|
|
|
|
|
// Shared queue name distributed messages across subscribers
|
|
|
|
func SubscriberQueue(n string) SubscriberOption {
|
|
|
|
return func(o *SubscriberOptions) {
|
|
|
|
o.Queue = n
|
|
|
|
}
|
|
|
|
}
|