1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/server/handler.go

67 lines
1.5 KiB
Go
Raw Normal View History

package server
import (
2015-11-20 18:17:33 +02:00
"github.com/micro/go-micro/registry"
)
2015-12-01 20:41:43 +02: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 20:45:52 +02:00
//
2015-12-01 20:41:43 +02:00
// Example:
2015-12-01 20:45:52 +02:00
//
// type Service struct {}
//
// func (s *Service) Method(context, request, response) error {
// return nil
// }
2015-12-01 20:41:43 +02:00
//
type Handler interface {
Name() string
Handler() interface{}
Endpoints() []*registry.Endpoint
Options() HandlerOptions
}
2015-12-01 20:41:43 +02:00
// Subscriber interface represents a subscription to a given topic using
// a specific subscriber function or object with methods.
type Subscriber interface {
Topic() string
Subscriber() interface{}
Endpoints() []*registry.Endpoint
Options() SubscriberOptions
}
type HandlerOptions struct {
Internal bool
}
type SubscriberOptions struct {
2016-01-22 23:48:43 +02:00
Queue string
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
}
}
// 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
}
}
2016-01-22 23:48:43 +02:00
// Shared queue name distributed messages across subscribers
func SubscriberQueue(n string) SubscriberOption {
return func(o *SubscriberOptions) {
o.Queue = n
}
}