Add client comments

This commit is contained in:
Asim 2015-11-26 12:21:00 +00:00
parent 24b8cd3d97
commit ad6e8194ed
2 changed files with 18 additions and 6 deletions

View File

@ -41,42 +41,55 @@ var (
DefaultClient Client = newRpcClient() DefaultClient Client = newRpcClient()
) )
// Makes a synchronous call to a service using the default client
func Call(ctx context.Context, request Request, response interface{}) error { func Call(ctx context.Context, request Request, response interface{}) error {
return DefaultClient.Call(ctx, request, response) return DefaultClient.Call(ctx, request, response)
} }
// Makes a synchronous call to the specified address using the default client
func CallRemote(ctx context.Context, address string, request Request, response interface{}) error { func CallRemote(ctx context.Context, address string, request Request, response interface{}) error {
return DefaultClient.CallRemote(ctx, address, request, response) return DefaultClient.CallRemote(ctx, address, request, response)
} }
// Creates a streaming connection with a service and returns responses on the
// channel passed in. It's upto the user to close the streamer.
func Stream(ctx context.Context, request Request, responseChan interface{}) (Streamer, error) { func Stream(ctx context.Context, request Request, responseChan interface{}) (Streamer, error) {
return DefaultClient.Stream(ctx, request, responseChan) return DefaultClient.Stream(ctx, request, responseChan)
} }
// Creates a streaming connection to the address specified.
func StreamRemote(ctx context.Context, address string, request Request, responseChan interface{}) (Streamer, error) { func StreamRemote(ctx context.Context, address string, request Request, responseChan interface{}) (Streamer, error) {
return DefaultClient.StreamRemote(ctx, address, request, responseChan) return DefaultClient.StreamRemote(ctx, address, request, responseChan)
} }
// Publishes a publication using the default client. Using the underlying broker
// set within the options.
func Publish(ctx context.Context, p Publication) error { func Publish(ctx context.Context, p Publication) error {
return DefaultClient.Publish(ctx, p) return DefaultClient.Publish(ctx, p)
} }
// Creates a new client with the options passed in
func NewClient(opt ...Option) Client { func NewClient(opt ...Option) Client {
return newRpcClient(opt...) return newRpcClient(opt...)
} }
// Creates a new publication using the default client
func NewPublication(topic string, message interface{}) Publication { func NewPublication(topic string, message interface{}) Publication {
return DefaultClient.NewPublication(topic, message) return DefaultClient.NewPublication(topic, message)
} }
// Creates a new request using the default client. Content Type will
// be set to the default within options and use the appropriate codec
func NewRequest(service, method string, request interface{}) Request { func NewRequest(service, method string, request interface{}) Request {
return DefaultClient.NewRequest(service, method, request) return DefaultClient.NewRequest(service, method, request)
} }
// Creates a new protobuf request using the default client
func NewProtoRequest(service, method string, request interface{}) Request { func NewProtoRequest(service, method string, request interface{}) Request {
return DefaultClient.NewProtoRequest(service, method, request) return DefaultClient.NewProtoRequest(service, method, request)
} }
// Creates a new json request using the default client
func NewJsonRequest(service, method string, request interface{}) Request { func NewJsonRequest(service, method string, request interface{}) Request {
return DefaultClient.NewJsonRequest(service, method, request) return DefaultClient.NewJsonRequest(service, method, request)
} }

View File

@ -1,15 +1,14 @@
/* /*
Server represents a server instance in go-micro which handles synchronous Server represents a server instance in go-micro which handles synchronous
requests via handlers and asynchronous requests via subscribers that requests via handlers and asynchronous requests via subscribers that
register with a broker. register with a broker.
The server combines the all the packages in go-micro to create a whole unit The server combines the all the packages in go-micro to create a whole unit
used for building applications including discovery, client/server communication used for building applications including discovery, client/server communication
and pub/sub. and pub/sub.
*/ */
package server package server
import ( import (
"os" "os"
"os/signal" "os/signal"