rest2go icon indicating copy to clipboard operation
rest2go copied to clipboard

server as struct

Open Kissaki opened this issue 14 years ago • 2 comments

Is there a valid reason for using functions only? Using a struct for the REST-server would be better style and clear.

Client is a struct. Why not server?

Kissaki avatar Jun 09 '11 14:06 Kissaki

The "server" only does one thing. It routes HTTP requests. It doesn't do anything else. The data needed to make that mapping is stored in a package global map (resources).

The server (excluding helper methods) consists of two functions: resourceHandler and Resource.

Resource registers a path (for a resource) with the http package and sets resourceHandler as the handler. It also stores the mapping between a resource name (the path) and the object which has the functions to call.

resourceHandler is called by the http package when a registered route (in http) is requested. It then figures out which object (resource) should respond to that request and makes the right function call.

The resource can be a struct. It can be any whatever data type you need to represent your resource.

Nathan

On Thu, Jun 9, 2011 at 16:29, Kissaki [email protected] wrote:

Is there a valid reason for using functions only? Using a struct for the REST-server would be better style and clear.

Client is a struct. Why not server?

Reply to this email directly or view it on GitHub: https://github.com/Kissaki/rest.go/issues/13

nathankerr avatar Jun 09 '11 14:06 nathankerr

Yeah. So, what speaks for not defining a struct is that it is just 2 methods. Anything else?

Kissaki avatar Jun 09 '11 22:06 Kissaki