Rename status.Message to status.Meta

This commit is contained in:
Adnan Maolood 2021-01-10 00:10:57 -05:00
parent f2921a396f
commit 3ed39e62d8
3 changed files with 8 additions and 21 deletions

View File

@ -146,7 +146,7 @@ func main() {
} }
fmt.Print(string(body)) fmt.Print(string(body))
} else { } else {
fmt.Printf("%d %s: %s\n", resp.Status, resp.Status.Message(), resp.Meta) fmt.Printf("%d %s\n", resp.Status, resp.Meta)
os.Exit(1) os.Exit(1)
} }
} }

View File

@ -266,15 +266,10 @@ func (w *ResponseWriter) Header(status Status, meta string) {
// Status sets the response header to the given status code. // Status sets the response header to the given status code.
// //
// Status is equivalent to Header(status, status.Message()) // Status is equivalent to Header(status, status.Meta())
func (w *ResponseWriter) Status(status Status) { func (w *ResponseWriter) Status(status Status) {
meta := status.Message() w.status = status
w.meta = status.Meta()
if status.Class() == StatusClassSuccess {
meta = w.mediatype
}
w.Header(status, meta)
} }
// SetMediaType sets the media type that will be written for a successful response. // SetMediaType sets the media type that will be written for a successful response.

View File

@ -41,19 +41,11 @@ func (s Status) Class() StatusClass {
return StatusClass(s / 10) return StatusClass(s / 10)
} }
// Message returns a status message corresponding to this status code. // Meta returns a description of the status code appropriate for use in a response.
func (s Status) Message() string { //
// Meta returns an empty string for input, success, and redirect status codes.
func (s Status) Meta() string {
switch s { switch s {
case StatusInput:
return "Input"
case StatusSensitiveInput:
return "Sensitive input"
case StatusSuccess:
return "Success"
case StatusRedirect:
return "Redirect"
case StatusPermanentRedirect:
return "Permanent redirect"
case StatusTemporaryFailure: case StatusTemporaryFailure:
return "Temporary failure" return "Temporary failure"
case StatusServerUnavailable: case StatusServerUnavailable: