Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 400aa93

Browse files
author
Josh Cave
committed
static file, and binary data shortcuts. also tidyed up scheme on url http vs https
1 parent 12a6d5e commit 400aa93

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

flow.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"io"
7+
"io/ioutil"
78
"net/http"
89
"net/url"
910
"runtime"
@@ -244,7 +245,24 @@ func (flow *Flow) Redirect(newUrl string, status int) {
244245
http.Redirect(flow.respWrt, flow.req, newUrl, status)
245246
return
246247
}
247-
flow.ErrorHTML(http.StatusInternalServerError, "Invalid Redirect", nil)
248+
flow.ErrorText(http.StatusInternalServerError, "Invalid Redirect", nil)
249+
}
250+
251+
func (flow *Flow) StaticFile(status int, filepath string, mime string) {
252+
file, err := ioutil.ReadFile(filepath)
253+
if err != nil {
254+
flow.ErrorText(500, "Failed to load %s", err)
255+
return
256+
}
257+
flow.respWrt.Header().Add("content-type", mime)
258+
err = flow.Renderer.Data(flow.respWrt, status, file)
259+
flow.catchAfterErr(err)
260+
}
261+
262+
func (flow *Flow) Data(status int, bytes []byte, mime string) {
263+
flow.respWrt.Header().Add("content-type", mime)
264+
err := flow.Renderer.Data(flow.respWrt, status, bytes)
265+
flow.catchAfterErr(err)
248266
}
249267

250268
func (flow *Flow) File(bytes []byte, filename string, mime string) {

0 commit comments

Comments
 (0)