-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhandling_text.go
33 lines (28 loc) · 1.06 KB
/
handling_text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package gimlet
import (
"net/http"
)
// WriteTextResponse writes data to the response body with the given
// code as plain text after attempting to convert the data to a byte
// array.
func WriteTextResponse(w http.ResponseWriter, code int, data interface{}) {
writeResponse(TEXT, w, code, data)
}
// WriteText writes the data, converted to text as possible, to the response body, with a successful
// status code.
func WriteText(w http.ResponseWriter, data interface{}) {
// 200
WriteTextResponse(w, http.StatusOK, data)
}
// WriteTextError write the data, converted to text as possible, to the response body with a
// bad-request (e.g. 400) response code.
func WriteTextError(w http.ResponseWriter, data interface{}) {
// 400
WriteTextResponse(w, http.StatusBadRequest, data)
}
// WriteTextInternalError write the data, converted to text as possible, to the response body with an
// internal server error (e.g. 500) response code.
func WriteTextInternalError(w http.ResponseWriter, data interface{}) {
// 500
WriteTextResponse(w, http.StatusInternalServerError, data)
}