add comments

This commit is contained in:
Asim 2015-11-26 00:13:17 +00:00
parent 40fea1ac24
commit 96955dbd53

View File

@ -32,10 +32,12 @@ var (
DefaultServer Server = newRpcServer() DefaultServer Server = newRpcServer()
) )
// Returns config options for the default service
func Config() options { func Config() options {
return DefaultServer.Config() return DefaultServer.Config()
} }
// Initialises the default server with options passed in
func Init(opt ...Option) { func Init(opt ...Option) {
if DefaultServer == nil { if DefaultServer == nil {
DefaultServer = newRpcServer(opt...) DefaultServer = newRpcServer(opt...)
@ -43,34 +45,46 @@ func Init(opt ...Option) {
DefaultServer.Init(opt...) DefaultServer.Init(opt...)
} }
// Returns a new server with options passed in
func NewServer(opt ...Option) Server { func NewServer(opt ...Option) Server {
return newRpcServer(opt...) return newRpcServer(opt...)
} }
// Creates a new subscriber interface with the given topic
// and handler using the default server
func NewSubscriber(topic string, h interface{}) Subscriber { func NewSubscriber(topic string, h interface{}) Subscriber {
return DefaultServer.NewSubscriber(topic, h) return DefaultServer.NewSubscriber(topic, h)
} }
// Creates a new handler interface using the default server
func NewHandler(h interface{}) Handler { func NewHandler(h interface{}) Handler {
return DefaultServer.NewHandler(h) return DefaultServer.NewHandler(h)
} }
// Registers a handler interface with the default server to
// handle inbound requests
func Handle(h Handler) error { func Handle(h Handler) error {
return DefaultServer.Handle(h) return DefaultServer.Handle(h)
} }
// Registers a subscriber interface with the default server
// which subscribes to specified topic with the broker
func Subscribe(s Subscriber) error { func Subscribe(s Subscriber) error {
return DefaultServer.Subscribe(s) return DefaultServer.Subscribe(s)
} }
// Registers the default server with the discovery system
func Register() error { func Register() error {
return DefaultServer.Register() return DefaultServer.Register()
} }
// Deregisters the default server from the discovery system
func Deregister() error { func Deregister() error {
return DefaultServer.Deregister() return DefaultServer.Deregister()
} }
// Blocking run starts the default server and waits for a kill
// signal before exiting. Also registers/deregisters the server
func Run() error { func Run() error {
if err := Start(); err != nil { if err := Start(); err != nil {
return err return err
@ -91,12 +105,14 @@ func Run() error {
return Stop() return Stop()
} }
// Starts the default server
func Start() error { func Start() error {
config := DefaultServer.Config() config := DefaultServer.Config()
log.Infof("Starting server %s id %s", config.Name(), config.Id()) log.Infof("Starting server %s id %s", config.Name(), config.Id())
return DefaultServer.Start() return DefaultServer.Start()
} }
// Stops the default server
func Stop() error { func Stop() error {
log.Infof("Stopping server") log.Infof("Stopping server")
return DefaultServer.Stop() return DefaultServer.Stop()