Documentation ¶
Overview ¶
Package web defines utility functions for exposing services over HTTP.
Index ¶
- Variables
- func Arg(r *http.Request, name string) string
- func ArgOrNil(r *http.Request, name string) *string
- func Call(server, method string, req, reply proto.Message) error
- func ReadJSONBody(r *http.Request, msg proto.Message) error
- func RegisterQuitHandler(mux *http.ServeMux)
- func WriteJSONResponse(w http.ResponseWriter, r *http.Request, v interface{}) error
- func WriteProtoResponse(w http.ResponseWriter, r *http.Request, msg proto.Message) error
- func WriteResponse(w http.ResponseWriter, r *http.Request, msg proto.Message) error
Constants ¶
This section is empty.
Variables ¶
var JSONMarshaler = jsonpb.Marshaler{ OrigName: true, }
JSONMarshaler is the marshaler used to encode all JSON web requests.
Functions ¶
func ArgOrNil ¶
ArgOrNil returns a pointer to first query value for the named parameter or nil if it was not set.
func Call ¶
Call sends req to the given server method as a JSON-encoded body and unmarshals the response body as JSON into reply.
func ReadJSONBody ¶
ReadJSONBody reads the entire body of r and unmarshals it from JSON into msg. If the request body is empty, no error is returned and msg is unchanged.
func RegisterQuitHandler ¶
RegisterQuitHandler adds a handler for /quitquitquit that call os.Exit(0).
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, r *http.Request, v interface{}) error
WriteJSONResponse encodes v as JSON and writes it to w.
func WriteProtoResponse ¶
WriteProtoResponse serializes msg to w.
func WriteResponse ¶
WriteResponse writes msg to w as a serialized protobuf if the "proto" query parameter is set; otherwise as JSON.
Types ¶
This section is empty.