Declare option not options

This commit is contained in:
Asim 2015-05-21 19:28:57 +01:00
parent 9d514f0e60
commit 4f909d0be4
4 changed files with 16 additions and 4 deletions

View File

@ -16,12 +16,18 @@ type options struct {
transport transport.Transport transport transport.Transport
} }
type Options func(*options) type Option func(*options)
var ( var (
DefaultClient Client = NewRpcClient() DefaultClient Client = NewRpcClient()
) )
func Transport(t transport.Transport) Option {
return func(o *options) {
o.transport = t
}
}
func Call(request Request, response interface{}) error { func Call(request Request, response interface{}) error {
return DefaultClient.Call(request, response) return DefaultClient.Call(request, response)
} }

View File

@ -167,7 +167,7 @@ func (r *RpcClient) NewJsonRequest(service, method string, request interface{})
return newRpcRequest(service, method, request, "application/json") return newRpcRequest(service, method, request, "application/json")
} }
func NewRpcClient(opt ...Options) *RpcClient { func NewRpcClient(opt ...Option) *RpcClient {
var opts options var opts options
for _, o := range opt { for _, o := range opt {

View File

@ -123,7 +123,7 @@ func (s *RpcServer) Stop() error {
return <-ch return <-ch
} }
func NewRpcServer(address string, opt ...Options) *RpcServer { func NewRpcServer(address string, opt ...Option) *RpcServer {
var opts options var opts options
for _, o := range opt { for _, o := range opt {

View File

@ -27,7 +27,7 @@ type options struct {
transport transport.Transport transport transport.Transport
} }
type Options func(*options) type Option func(*options)
var ( var (
Address string Address string
@ -36,6 +36,12 @@ var (
DefaultServer Server DefaultServer Server
) )
func Transport(t transport.Transport) Option {
return func(o *options) {
o.transport = t
}
}
func Init() error { func Init() error {
defer log.Flush() defer log.Flush()