Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
3fa6dcac
Commit
3fa6dcac
authored
Nov 18, 2010
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: add RegisterName to allow override of default type name
R=r, r2 CC=golang-dev
https://golang.org/cl/2890041
parent
6aeaa5d3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
+23
-8
server.go
src/pkg/rpc/server.go
+23
-8
No files found.
src/pkg/rpc/server.go
View file @
3fa6dcac
...
...
@@ -199,7 +199,19 @@ func isExported(name string) bool {
// - one return value, of type os.Error
// It returns an error if the receiver is not an exported type or has no
// suitable methods.
// The client accesses each method using a string of the form "Type.Method",
// where Type is the receiver's concrete type.
func
(
server
*
Server
)
Register
(
rcvr
interface
{})
os
.
Error
{
return
server
.
register
(
rcvr
,
""
,
false
)
}
// RegisterName is like Register but uses the provided name for the type
// instead of the receiver's concrete type.
func
(
server
*
Server
)
RegisterName
(
name
string
,
rcvr
interface
{})
os
.
Error
{
return
server
.
register
(
rcvr
,
name
,
true
)
}
func
(
server
*
Server
)
register
(
rcvr
interface
{},
name
string
,
useName
bool
)
os
.
Error
{
server
.
Lock
()
defer
server
.
Unlock
()
if
server
.
serviceMap
==
nil
{
...
...
@@ -209,10 +221,13 @@ func (server *Server) Register(rcvr interface{}) os.Error {
s
.
typ
=
reflect
.
Typeof
(
rcvr
)
s
.
rcvr
=
reflect
.
NewValue
(
rcvr
)
sname
:=
reflect
.
Indirect
(
s
.
rcvr
)
.
Type
()
.
Name
()
if
useName
{
sname
=
name
}
if
sname
==
""
{
log
.
Exit
(
"rpc: no service name for type"
,
s
.
typ
.
String
())
}
if
s
.
typ
.
PkgPath
()
!=
""
&&
!
isExported
(
sname
)
{
if
s
.
typ
.
PkgPath
()
!=
""
&&
!
isExported
(
sname
)
&&
!
useName
{
s
:=
"rpc Register: type "
+
sname
+
" is not exported"
log
.
Print
(
s
)
return
os
.
ErrorString
(
s
)
...
...
@@ -429,15 +444,15 @@ func (server *Server) Accept(lis net.Listener) {
}
}
// Register publishes in the DefaultServer the set of methods
// of the receiver value that satisfy the following conditions:
// - exported method
// - two arguments, both pointers to exported structs
// - one return value, of type os.Error
// It returns an error if the receiver is not an exported type or has no
// suitable methods.
// Register publishes the receiver's methods in the DefaultServer.
func
Register
(
rcvr
interface
{})
os
.
Error
{
return
DefaultServer
.
Register
(
rcvr
)
}
// RegisterName is like Register but uses the provided name for the type
// instead of the receiver's concrete type.
func
RegisterName
(
name
string
,
rcvr
interface
{})
os
.
Error
{
return
DefaultServer
.
RegisterName
(
name
,
rcvr
)
}
// A ServerCodec implements reading of RPC requests and writing of
// RPC responses for the server side of an RPC session.
// The server calls ReadRequestHeader and ReadRequestBody in pairs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment