From 1201293beadf46cdd5fda969dba71c7250f89e45 Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 14 Dec 2024 21:56:23 +0700 Subject: [PATCH] :recycle: refactor: refactor codebase #2 --- wrap.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wrap.go b/wrap.go index a8c24b0..f5cb16f 100644 --- a/wrap.go +++ b/wrap.go @@ -1,6 +1,7 @@ package wrapify import ( + "fmt" "net/http" "time" @@ -78,6 +79,22 @@ func (w *wrapper) StatusCode() int { return w.statusCode } +// StatusText returns a human-readable string representation of the HTTP status. +// +// This function combines the status code with its associated status text, which +// is retrieved using the `http.StatusText` function from the `net/http` package. +// The returned string follows the format "statusCode (statusText)". +// +// For example, if the status code is 200, the function will return "200 (OK)". +// If the status code is 404, it will return "404 (Not Found)". +// +// Returns: +// - A string formatted as "statusCode (statusText)", where `statusCode` is the +// numeric HTTP status code and `statusText` is the corresponding textual description. +func (w *wrapper) StatusText() string { + return fmt.Sprintf("%d (%s)", w.StatusCode(), http.StatusText(w.StatusCode())) +} + // Message retrieves the message associated with the `wrapper` instance. // // This function returns the `message` field of the `wrapper`, which typically