@@ -40,8 +40,9 @@ type CodecRequest interface {
4040// NewServer returns a new RPC server.
4141func NewServer () * Server {
4242 return & Server {
43- codecs : make (map [string ]Codec ),
44- services : new (serviceMap ),
43+ codecs : make (map [string ]Codec ),
44+ services : new (serviceMap ),
45+ concatStyle : "." ,
4546 }
4647}
4748
@@ -60,6 +61,16 @@ type Server struct {
6061 interceptFunc func (i * RequestInfo ) * http.Request
6162 beforeFunc func (i * RequestInfo )
6263 afterFunc func (i * RequestInfo )
64+ concatStyle string // The style used to concatenate service and method names, e.g., "Service.Method" or "Service/Method"
65+ }
66+
67+ // SetConcatStyle sets the style used to concatenate service and method names.
68+ // The default style is ".".
69+ // This is useful when you want to use a different style, such as "/".
70+ // The style is used in the method name, e.g., "Service.Method" or "Service/Method".
71+ func (s * Server ) SetConcatStyle (concatStyle string ) * Server {
72+ s .concatStyle = concatStyle
73+ return s
6374}
6475
6576// RegisterCodec adds a new codec to the server.
@@ -78,13 +89,13 @@ func (s *Server) RegisterCodec(codec Codec, contentType string) {
7889//
7990// Methods from the receiver will be extracted if these rules are satisfied:
8091//
81- // - The receiver is exported (begins with an upper case letter) or local
82- // (defined in the package registering the service).
83- // - The method name is exported.
84- // - The method has three arguments: *http.Request, *args, *reply.
85- // - All three arguments are pointers.
86- // - The second and third arguments are exported or local.
87- // - The method has return type error.
92+ // - The receiver is exported (begins with an upper case letter) or local
93+ // (defined in the package registering the service).
94+ // - The method name is exported.
95+ // - The method has three arguments: *http.Request, *args, *reply.
96+ // - All three arguments are pointers.
97+ // - The second and third arguments are exported or local.
98+ // - The method has return type error.
8899//
89100// All other methods are ignored.
90101func (s * Server ) RegisterService (receiver interface {}, name string ) error {
@@ -99,13 +110,13 @@ func (s *Server) RegisterService(receiver interface{}, name string) error {
99110//
100111// Methods from the receiver will be extracted if these rules are satisfied:
101112//
102- // - The receiver is exported (begins with an upper case letter) or local
103- // (defined in the package registering the service).
104- // - The method name is exported.
105- // - The method has two arguments: *args, *reply.
106- // - Both arguments are pointers.
107- // - Both arguments are exported or local.
108- // - The method has return type error.
113+ // - The receiver is exported (begins with an upper case letter) or local
114+ // (defined in the package registering the service).
115+ // - The method name is exported.
116+ // - The method has two arguments: *args, *reply.
117+ // - Both arguments are pointers.
118+ // - Both arguments are exported or local.
119+ // - The method has return type error.
109120//
110121// All other methods are ignored.
111122func (s * Server ) RegisterTCPService (receiver interface {}, name string ) error {
@@ -116,7 +127,7 @@ func (s *Server) RegisterTCPService(receiver interface{}, name string) error {
116127//
117128// The method uses a dotted notation as in "Service.Method".
118129func (s * Server ) HasMethod (method string ) bool {
119- if _ , _ , err := s .services .get (method ); err == nil {
130+ if _ , _ , err := s .services .get (method , s . concatStyle ); err == nil {
120131 return true
121132 }
122133 return false
@@ -180,7 +191,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
180191 s .writeError (w , 400 , errMethod .Error ())
181192 return
182193 }
183- serviceSpec , methodSpec , errGet := s .services .get (method )
194+ serviceSpec , methodSpec , errGet := s .services .get (method , s . concatStyle )
184195 if errGet != nil {
185196 s .writeError (w , 400 , errGet .Error ())
186197 return
0 commit comments