web

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2015 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Overview

Package web defines utility functions for exposing services over HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

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 interface{}) 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, v interface{}) error

ReadJSONBody reads the entire body of r and unmarshals it from JSON into v. If the request body is empty, no error is returned and v 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