prototyped svg reports
This commit is contained in:
@@ -47,6 +47,10 @@ func (b bodyRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(b)
|
||||
}
|
||||
|
||||
func (b bodyRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(b)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ func (c cookieRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(c)
|
||||
}
|
||||
|
||||
func (c cookieRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(c)
|
||||
}
|
||||
|
||||
func (c cookieRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(c)
|
||||
}
|
||||
|
||||
@@ -103,6 +103,10 @@ func (h headerRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(h)
|
||||
}
|
||||
|
||||
func (h headerRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(h)
|
||||
}
|
||||
|
||||
func (h headerRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(h)
|
||||
}
|
||||
|
||||
+23
-3
@@ -11,8 +11,9 @@ import (
|
||||
|
||||
type (
|
||||
htmlRes struct {
|
||||
body []byte
|
||||
res Response
|
||||
body []byte
|
||||
reader io.Reader
|
||||
res Response
|
||||
}
|
||||
)
|
||||
|
||||
@@ -24,6 +25,12 @@ func HTML(body []byte) Response {
|
||||
}
|
||||
}
|
||||
|
||||
func HTMLReader(body io.Reader) Response {
|
||||
return htmlRes{
|
||||
reader: body,
|
||||
}
|
||||
}
|
||||
|
||||
func (h htmlRes) String() string {
|
||||
if h.res != nil {
|
||||
return fmt.Sprintf(`{"body": %q, "nested": %s}`, string(h.body), h.res)
|
||||
@@ -46,6 +53,13 @@ func (h htmlRes) Redirect(code redirect.Code, to string) Response {
|
||||
|
||||
func (h htmlRes) HTML(body []byte) Response {
|
||||
h.body = body
|
||||
h.reader = nil
|
||||
return h
|
||||
}
|
||||
|
||||
func (h htmlRes) HTMLReader(body io.Reader) Response {
|
||||
h.body = nil
|
||||
h.reader = body
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -133,7 +147,13 @@ func (h htmlRes) GetRedirect() (code redirect.Code, to string, ok bool) {
|
||||
}
|
||||
|
||||
func (h htmlRes) getBody() (body io.ReadCloser, ok bool, err error) {
|
||||
return io.NopCloser(bytes.NewBuffer(h.body)), true, nil
|
||||
var r io.Reader
|
||||
if h.reader != nil {
|
||||
r = h.reader
|
||||
} else {
|
||||
r = bytes.NewBuffer(h.body)
|
||||
}
|
||||
return io.NopCloser(r), true, nil
|
||||
}
|
||||
|
||||
func (h htmlRes) getCookies() []http.Cookie {
|
||||
|
||||
@@ -49,6 +49,10 @@ func (j jsonRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(j)
|
||||
}
|
||||
|
||||
func (j jsonRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(j)
|
||||
}
|
||||
|
||||
func (j jsonRes) JSON(body any) Response {
|
||||
j.body = body
|
||||
return j
|
||||
|
||||
@@ -88,6 +88,10 @@ func (r redirectRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(r)
|
||||
}
|
||||
|
||||
func (r redirectRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(r)
|
||||
}
|
||||
|
||||
func (r redirectRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(r)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type (
|
||||
Redirect(code redirect.Code, to string) Response
|
||||
Body(io.ReadCloser) Response
|
||||
HTML([]byte) Response
|
||||
HTMLReader(io.Reader) Response
|
||||
JSON(any) Response
|
||||
Cookie(http.Cookie) Response
|
||||
|
||||
|
||||
@@ -64,6 +64,10 @@ func (s statusRes) HTML(body []byte) Response {
|
||||
return HTML(body).wrap(s)
|
||||
}
|
||||
|
||||
func (s statusRes) HTMLReader(body io.Reader) Response {
|
||||
return HTMLReader(body).wrap(s)
|
||||
}
|
||||
|
||||
func (s statusRes) JSON(body any) Response {
|
||||
return JSON(body).wrap(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user