Link Search Menu Expand Document

Back-end server

gosp-server, Go Server Pages’s back-end server, loads a plugin generated by the page compiler and uses it to service page requests. There is virtually no need to run it explicitly, though. It will normally be run implicitly either by the Apache module or by an invocation of gosp2go --run.

The back-end server accepts requests in JSON format, specifically a record containing a gosp.RequestData, a Boolean GetPID flag, and a Boolean ExitNow flag. If GetPID is true, the server will respond with the string gosp-pid and its process ID. This can be used to confirm that the server is running. If ExitNow is true, the server will stop accepting new requests, wait until all current requests complete, respond as in the GetPID case, and exit cleanly. Otherwise, it invokes the plugin-provided GospGeneratePage function, passing it the gosp.RequestData, a *bytes.Buffer to use for data output (gospOut), and a gosp.Metadata (really a channel of type gosp.KeyValue) to use for HTTP metadata output. When GospGeneratePage returns, if the HTTP metadata indicates a status code of anything except OK (200), the server discards the data and returns only the metadata.

If run with --socket=filename, gosp-server accepts JSON requests from local (e.g., Unix-domain) socket filename and sends back its response via a corresponding local socket. This is how the Apache module launches gosp-server. If run with --file=filename, gosp-server reads a JSON request from file filename and outputs its response to the standard output device. If neither --socket nor --file is specified, gosp-server passes an empty request to GospGeneratePage. This is how gosp2go launches gosp-server. The gosp-server(1) man page lists all gosp-server command-line options.

The source code for the back-end server lies in the gosp-server directory.