2016-12-14 18:41:48 +03:00
|
|
|
// Package server is an interface for a micro server
|
2015-01-14 02:31:27 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-03-03 14:53:52 +03:00
|
|
|
"context"
|
2015-01-14 02:31:27 +03:00
|
|
|
|
2015-08-26 14:15:37 +03:00
|
|
|
"github.com/pborman/uuid"
|
2015-01-14 02:31:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Server interface {
|
2015-12-31 21:11:46 +03:00
|
|
|
Options() Options
|
2016-01-02 22:12:17 +03:00
|
|
|
Init(...Option) error
|
2015-06-03 03:25:37 +03:00
|
|
|
Handle(Handler) error
|
2016-01-08 17:02:32 +03:00
|
|
|
NewHandler(interface{}, ...HandlerOption) Handler
|
|
|
|
NewSubscriber(string, interface{}, ...SubscriberOption) Subscriber
|
2015-06-12 21:52:27 +03:00
|
|
|
Subscribe(Subscriber) error
|
2015-06-03 03:25:37 +03:00
|
|
|
Register() error
|
|
|
|
Deregister() error
|
2015-01-14 02:31:27 +03:00
|
|
|
Start() error
|
|
|
|
Stop() error
|
2015-12-20 00:56:14 +03:00
|
|
|
String() string
|
2015-01-14 02:31:27 +03:00
|
|
|
}
|
|
|
|
|
2018-04-14 20:21:02 +03:00
|
|
|
type Message interface {
|
2015-12-02 23:56:50 +03:00
|
|
|
Topic() string
|
2018-04-14 20:21:02 +03:00
|
|
|
Payload() interface{}
|
2015-12-02 23:56:50 +03:00
|
|
|
ContentType() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Request interface {
|
|
|
|
Service() string
|
|
|
|
Method() string
|
|
|
|
ContentType() string
|
|
|
|
Request() interface{}
|
2015-12-17 23:37:35 +03:00
|
|
|
// indicates whether the request will be streamed
|
2015-12-02 23:56:50 +03:00
|
|
|
Stream() bool
|
|
|
|
}
|
|
|
|
|
2018-04-14 20:15:09 +03:00
|
|
|
// Stream represents a stream established with a client.
|
2015-12-17 23:37:35 +03:00
|
|
|
// A stream can be bidirectional which is indicated by the request.
|
|
|
|
// The last error will be left in Error().
|
|
|
|
// EOF indicated end of the stream.
|
2018-04-14 20:15:09 +03:00
|
|
|
type Stream interface {
|
2015-12-17 23:37:35 +03:00
|
|
|
Context() context.Context
|
|
|
|
Request() Request
|
|
|
|
Send(interface{}) error
|
|
|
|
Recv(interface{}) error
|
|
|
|
Error() error
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2015-12-31 21:11:46 +03:00
|
|
|
type Option func(*Options)
|
2015-05-21 21:24:57 +03:00
|
|
|
|
2016-01-08 17:02:32 +03:00
|
|
|
type HandlerOption func(*HandlerOptions)
|
|
|
|
|
|
|
|
type SubscriberOption func(*SubscriberOptions)
|
|
|
|
|
2015-01-14 02:31:27 +03:00
|
|
|
var (
|
2015-05-27 00:39:48 +03:00
|
|
|
DefaultAddress = ":0"
|
|
|
|
DefaultName = "go-server"
|
2015-06-03 03:25:37 +03:00
|
|
|
DefaultVersion = "1.0.0"
|
2015-05-27 00:39:48 +03:00
|
|
|
DefaultId = uuid.NewUUID().String()
|
|
|
|
DefaultServer Server = newRpcServer()
|
2015-01-14 02:31:27 +03:00
|
|
|
)
|
|
|
|
|
2016-04-06 20:03:27 +03:00
|
|
|
// NewServer returns a new server with options passed in
|
2015-05-27 00:39:48 +03:00
|
|
|
func NewServer(opt ...Option) Server {
|
|
|
|
return newRpcServer(opt...)
|
2015-05-23 19:40:53 +03:00
|
|
|
}
|