Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1282)

Side by Side Diff: src/pkg/net/rpc/jsonrpc/client.go

Issue 10704046: code review 10704046: net/rpc/jsonrpc: Add HTTP support (Closed)
Patch Set: diff -r 166d946fa77f http://code.google.com/p/go Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/rpc/jsonrpc/all_test.go ('k') | src/pkg/net/rpc/jsonrpc/server.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec 5 // Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec
6 // for the rpc package. 6 // for the rpc package.
7 package jsonrpc 7 package jsonrpc
8 8
9 import ( 9 import (
10 "encoding/json" 10 "encoding/json"
(...skipping 16 matching lines...) Expand all
27 // JSON-RPC responses include the request id but not the request method. 27 // JSON-RPC responses include the request id but not the request method.
28 // Package rpc expects both. 28 // Package rpc expects both.
29 // We save the request method in pending when sending a request 29 // We save the request method in pending when sending a request
30 // and then look it up by request ID when filling out the rpc Response. 30 // and then look it up by request ID when filling out the rpc Response.
31 mutex sync.Mutex // protects pending 31 mutex sync.Mutex // protects pending
32 pending map[uint64]string // map request id to method name 32 pending map[uint64]string // map request id to method name
33 } 33 }
34 34
35 // NewClientCodec returns a new rpc.ClientCodec using JSON-RPC on conn. 35 // NewClientCodec returns a new rpc.ClientCodec using JSON-RPC on conn.
36 func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec { 36 func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
37 return newClientCodec(conn)
38 }
39
40 func newClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
37 return &clientCodec{ 41 return &clientCodec{
38 dec: json.NewDecoder(conn), 42 dec: json.NewDecoder(conn),
39 enc: json.NewEncoder(conn), 43 enc: json.NewEncoder(conn),
40 c: conn, 44 c: conn,
41 pending: make(map[uint64]string), 45 pending: make(map[uint64]string),
42 } 46 }
43 } 47 }
44 48
45 type clientRequest struct { 49 type clientRequest struct {
46 Method string `json:"method"` 50 Method string `json:"method"`
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 118 }
115 119
116 // Dial connects to a JSON-RPC server at the specified network address. 120 // Dial connects to a JSON-RPC server at the specified network address.
117 func Dial(network, address string) (*rpc.Client, error) { 121 func Dial(network, address string) (*rpc.Client, error) {
118 conn, err := net.Dial(network, address) 122 conn, err := net.Dial(network, address)
119 if err != nil { 123 if err != nil {
120 return nil, err 124 return nil, err
121 } 125 }
122 return NewClient(conn), err 126 return NewClient(conn), err
123 } 127 }
128
129 type jsonClientCodecFactory int
130
131 func (_ *jsonClientCodecFactory) NewClientCodec(conn io.ReadWriteCloser) rpc.Cli entCodec {
132 return newClientCodec(conn)
133 }
134
135 // NewClientCodecFactory returns a json NewClientCodec factory.
136 func NewClientCodecFactory() rpc.ClientCodecFactory {
137 return new(jsonClientCodecFactory)
138 }
OLDNEW
« no previous file with comments | « src/pkg/net/rpc/jsonrpc/all_test.go ('k') | src/pkg/net/rpc/jsonrpc/server.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b