|
6 | 6 | "net/http" |
7 | 7 | "path/filepath" |
8 | 8 |
|
9 | | - "fmt" |
10 | | - |
11 | 9 | "net/url" |
12 | 10 |
|
13 | 11 | "bytes" |
@@ -60,7 +58,7 @@ func (c *Context) Socket() *websocket.Conn { |
60 | 58 | return c.socket |
61 | 59 | } |
62 | 60 |
|
63 | | -// Path returns the registered path for a handler. |
| 61 | +// Path returns the registered path for the handler. |
64 | 62 | func (c *Context) Path() string { |
65 | 63 | return c.path |
66 | 64 | } |
@@ -134,31 +132,19 @@ func (c *Context) Render(code int, name string, data interface{}) (err error) { |
134 | 132 | return |
135 | 133 | } |
136 | 134 |
|
137 | | -// HTML formats according to a format specifier and sends HTML response with |
138 | | -// status code. |
139 | | -func (c *Context) HTML(code int, format string, a ...interface{}) (err error) { |
140 | | - buf := new(bytes.Buffer) |
141 | | - _, err = fmt.Fprintf(buf, format, a...) |
142 | | - if err != nil { |
143 | | - return err |
144 | | - } |
| 135 | +// HTML sends an HTTP response with status code. |
| 136 | +func (c *Context) HTML(code int, html string) (err error) { |
145 | 137 | c.response.Header().Set(ContentType, TextHTMLCharsetUTF8) |
146 | 138 | c.response.WriteHeader(code) |
147 | | - c.response.Write(buf.Bytes()) |
| 139 | + c.response.Write([]byte(html)) |
148 | 140 | return |
149 | 141 | } |
150 | 142 |
|
151 | | -// String formats according to a format specifier and sends text response with status |
152 | | -// code. |
153 | | -func (c *Context) String(code int, format string, a ...interface{}) (err error) { |
154 | | - buf := new(bytes.Buffer) |
155 | | - _, err = fmt.Fprintf(buf, format, a...) |
156 | | - if err != nil { |
157 | | - return err |
158 | | - } |
| 143 | +// String sends a string response with status code. |
| 144 | +func (c *Context) String(code int, s string) (err error) { |
159 | 145 | c.response.Header().Set(ContentType, TextPlain) |
160 | 146 | c.response.WriteHeader(code) |
161 | | - c.response.Write(buf.Bytes()) |
| 147 | + c.response.Write([]byte(s)) |
162 | 148 | return |
163 | 149 | } |
164 | 150 |
|
|
0 commit comments