Rename Meta to StatusText

Rename Meta to StatusText and support all status codes.
This commit is contained in:
Adnan Maolood 2021-02-17 12:06:22 -05:00
parent a3c1804395
commit ec22e762c3
2 changed files with 15 additions and 7 deletions

View File

@ -139,7 +139,7 @@ type ResponseWriter interface {
Header(status int, meta string) Header(status int, meta string)
// Status sets the response status code. // Status sets the response status code.
// It also sets the response meta to Meta(status). // It also sets the response meta to StatusText(status).
Status(status int) Status(status int)
// Meta sets the response meta. // Meta sets the response meta.
@ -195,7 +195,7 @@ func (w *responseWriter) Header(status int, meta string) {
func (w *responseWriter) Status(status int) { func (w *responseWriter) Status(status int) {
w.status = status w.status = status
w.meta = Meta(status) w.meta = StatusText(status)
} }
func (w *responseWriter) Meta(meta string) { func (w *responseWriter) Meta(meta string) {

View File

@ -28,12 +28,20 @@ func StatusClass(status int) int {
return (status / 10) * 10 return (status / 10) * 10
} }
// Meta returns a description of the provided status code appropriate // StatusText returns a text for the provided status code.
// for use in a response. // It returns the empty string if the status code is unknown.
// func StatusText(status int) string {
// Meta returns an empty string for input, success, and redirect status codes.
func Meta(status int) string {
switch status { switch status {
case StatusInput:
return "Input"
case StatusSensitiveInput:
return "Sensitive input"
case StatusSuccess:
return "Success"
case StatusRedirect:
return "Reidrect"
case StatusPermanentRedirect:
return "Permanent redirect"
case StatusTemporaryFailure: case StatusTemporaryFailure:
return "Temporary failure" return "Temporary failure"
case StatusServerUnavailable: case StatusServerUnavailable: