web

package
v0.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2016 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Overview

Package web defines utility functions for exposing services over HTTP.

Index

Constants

This section is empty.

Variables

View Source
var JSONMarshaler = jsonpb.Marshaler{}

JSONMarshaler is the marshaler used to encode all JSON web requests.

Functions

func Arg

func Arg(r *http.Request, name string) string

Arg returns the first query value for the named parameter or "" if it was not set.

func ArgOrNil

func ArgOrNil(r *http.Request, name string) *string

ArgOrNil returns a pointer to first query value for the named parameter or nil if it was not set.

func Call

func Call(server, method string, req, reply proto.Message) error

Call sends req to the given server method as a JSON-encoded body and unmarshals the response body as JSON into reply.

func ReadJSONBody

func ReadJSONBody(r *http.Request, msg proto.Message) error

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

func RegisterQuitHandler(mux *http.ServeMux)

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

func WriteProtoResponse(w http.ResponseWriter, r *http.Request, msg proto.Message) error

WriteProtoResponse serializes msg to w.

func WriteResponse

func WriteResponse(w http.ResponseWriter, r *http.Request, msg proto.Message) error

WriteResponse writes msg to w as a serialized protobuf if the "proto" query parameter is set; otherwise as JSON.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL