renamed site directory to server
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"ruben/inventory2/internal/server/redirect"
|
||||
)
|
||||
|
||||
type (
|
||||
bodyRes struct {
|
||||
body io.ReadCloser
|
||||
res Response
|
||||
}
|
||||
)
|
||||
|
||||
var _ Response = bodyRes{}
|
||||
|
||||
func Body(body io.ReadCloser) Response {
|
||||
return bodyRes{
|
||||
body: body,
|
||||
}
|
||||
}
|
||||
|
||||
func (b bodyRes) String() string {
|
||||
if b.res != nil {
|
||||
return fmt.Sprintf(`{"body": %q, "nested": %s}`, b.body, b.res)
|
||||
}
|
||||
return fmt.Sprintf(`{"body": %q}`, b.body)
|
||||
}
|
||||
|
||||
func (b bodyRes) wrap(res Response) Response {
|
||||
b.res = res
|
||||
return b
|
||||
}
|
||||
|
||||
func (b bodyRes) Status(code int) Response {
|
||||
return Status(code).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) Redirect(code redirect.Code, to string) Response {
|
||||
return Redirect(code, to).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) Body(body io.ReadCloser) Response {
|
||||
b.body = body
|
||||
return b
|
||||
}
|
||||
|
||||
func (b bodyRes) Cookie(ck http.Cookie) Response {
|
||||
return Cookie(ck).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) getStatus() (int, bool) {
|
||||
if b.res == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return b.res.getStatus()
|
||||
}
|
||||
|
||||
func (b bodyRes) getRedirect() (code redirect.Code, to string, ok bool) {
|
||||
if b.res == nil {
|
||||
return 0, "", false
|
||||
}
|
||||
|
||||
return b.res.getRedirect()
|
||||
}
|
||||
|
||||
func (b bodyRes) getBody() (body io.ReadCloser, ok bool, err error) {
|
||||
return b.body, true, nil
|
||||
}
|
||||
|
||||
func (b bodyRes) getCookies() []http.Cookie {
|
||||
if b.res != nil {
|
||||
return b.res.getCookies()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b bodyRes) getContentType() (contentType string, ok bool) {
|
||||
if b.res != nil {
|
||||
return b.res.getContentType()
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
Reference in New Issue
Block a user