Documentation ¶
Index ¶
- func HandleIDRequest(w http.ResponseWriter, r *http.Request, ...)
- func ServeCORS(w http.ResponseWriter, r *http.Request, m *mux.Router)
- func SetContentTypeForExtension(w http.ResponseWriter, page string)
- func TimestampToString(ts int) string
- func WriteBytes(w http.ResponseWriter, b []byte) (int, error)
- func WriteCSVData(w http.ResponseWriter, key []byte, d [][]string) error
- func WriteCloseResponse(err error, w http.ResponseWriter)
- func WriteErrorResponse(w http.ResponseWriter, e error) (int, error)
- func WriteHeader(w http.ResponseWriter, status ...int)
- func WriteJSONResponse(o interface{}, w http.ResponseWriter) error
- func WriteOKResponse(w http.ResponseWriter)
- func WriteRESTErrorResponse(w http.ResponseWriter, e error) (int, error)
- func WriteZippedBytes(w http.ResponseWriter, b []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleIDRequest ¶
func HandleIDRequest(w http.ResponseWriter, r *http.Request, f func(id int, w http.ResponseWriter, r *http.Request))
HandleIDRequest extracts the ID from the request and passes it to the handler function `f`
func ServeCORS ¶
ServeCORS enables all verbs when an OPTIONS is received. In other cases dispatches the request to Multiplexer
func SetContentTypeForExtension ¶
func SetContentTypeForExtension(w http.ResponseWriter, page string)
SetContentTypeForExtension sets the Content-Type header for the page based on the extension
func TimestampToString ¶
TimestampToString takes the Unix timestamp integer and formats it into a filename friendly string
func WriteBytes ¶
func WriteBytes(w http.ResponseWriter, b []byte) (int, error)
WriteBytes writes the slice `b` of bytes, handy for sending unmarshalled JSON. Returns the number of bytes written and an error if one happened.
func WriteCSVData ¶
func WriteCSVData(w http.ResponseWriter, key []byte, d [][]string) error
WriteCSVData writes the `d` arrays in CSV form as an attachment file named `key`.csv
func WriteCloseResponse ¶
func WriteCloseResponse(err error, w http.ResponseWriter)
WriteCloseResponse helper function as it was repeatedly being copy pasted.
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, e error) (int, error)
WriteErrorResponse writes a simple JSON error, we do not return a server error because the Server is working correctly - some other issue has arrisen
func WriteHeader ¶
func WriteHeader(w http.ResponseWriter, status ...int)
WriteHeader writes a defacto JSON CORs header, passing a `status value is optional`
func WriteJSONResponse ¶
func WriteJSONResponse(o interface{}, w http.ResponseWriter) error
WriteJSONResponse attempts to Marshal and write the object `o`
func WriteOKResponse ¶
func WriteOKResponse(w http.ResponseWriter)
WriteOKResponse for when everything went just fine - like a PUT.
func WriteRESTErrorResponse ¶
func WriteRESTErrorResponse(w http.ResponseWriter, e error) (int, error)
WriteRESTErrorResponse provides a "proper" error status
func WriteZippedBytes ¶
func WriteZippedBytes(w http.ResponseWriter, b []byte) (int, error)
WriteZippedBytes zips up the `b` array and writes it as a response Returns number of bytes written, and an error if any occured
Types ¶
This section is empty.