mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
Removed prinftf from Context#String and Context#HTML, #154
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
754c84596e
commit
f54cdd86d0
28
context.go
28
context.go
@ -6,8 +6,6 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"fmt"
|
||||
|
||||
"net/url"
|
||||
|
||||
"bytes"
|
||||
@ -60,7 +58,7 @@ func (c *Context) Socket() *websocket.Conn {
|
||||
return c.socket
|
||||
}
|
||||
|
||||
// Path returns the registered path for a handler.
|
||||
// Path returns the registered path for the handler.
|
||||
func (c *Context) Path() string {
|
||||
return c.path
|
||||
}
|
||||
@ -134,31 +132,19 @@ func (c *Context) Render(code int, name string, data interface{}) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// HTML formats according to a format specifier and sends HTML response with
|
||||
// status code.
|
||||
func (c *Context) HTML(code int, format string, a ...interface{}) (err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = fmt.Fprintf(buf, format, a...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// HTML sends an HTTP response with status code.
|
||||
func (c *Context) HTML(code int, html string) (err error) {
|
||||
c.response.Header().Set(ContentType, TextHTMLCharsetUTF8)
|
||||
c.response.WriteHeader(code)
|
||||
c.response.Write(buf.Bytes())
|
||||
c.response.Write([]byte(html))
|
||||
return
|
||||
}
|
||||
|
||||
// String formats according to a format specifier and sends text response with status
|
||||
// code.
|
||||
func (c *Context) String(code int, format string, a ...interface{}) (err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = fmt.Fprintf(buf, format, a...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// String sends a string response with status code.
|
||||
func (c *Context) String(code int, s string) (err error) {
|
||||
c.response.Header().Set(ContentType, TextPlain)
|
||||
c.response.WriteHeader(code)
|
||||
c.response.Write(buf.Bytes())
|
||||
c.response.Write([]byte(s))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
@ -39,8 +40,8 @@ func upload(c *echo.Context) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.",
|
||||
name, email, len(files))
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Thank You! %s <%s>, %d files uploaded successfully.",
|
||||
name, email, len(files)))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -1,13 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
mw "github.com/labstack/echo/middleware"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
mw "github.com/labstack/echo/middleware"
|
||||
)
|
||||
|
||||
func upload(c *echo.Context) error {
|
||||
@ -63,8 +65,8 @@ func upload(c *echo.Context) error {
|
||||
}
|
||||
i++
|
||||
}
|
||||
return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.",
|
||||
name, email, i)
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Thank You! %s <%s>, %d files uploaded successfully.",
|
||||
name, email, i))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -8,7 +8,7 @@ menu:
|
||||
|
||||
### Handler path
|
||||
|
||||
`Context#Path()` returns the registered path for a handler, it can be used in the
|
||||
`Context#Path()` returns the registered path for the handler, it can be used in the
|
||||
middleware for logging purpose.
|
||||
|
||||
*Example*
|
||||
|
@ -89,7 +89,7 @@ Sends an XML HTTP response with status code.
|
||||
Context.HTML(code int, html string) error
|
||||
```
|
||||
|
||||
Sends an HTML HTTP response with status code.
|
||||
Sends an HTML response with status code.
|
||||
|
||||
### String
|
||||
|
||||
@ -97,7 +97,7 @@ Sends an HTML HTTP response with status code.
|
||||
Context.String(code int, s string) error
|
||||
```
|
||||
|
||||
Sends a text/plain HTTP response with status code.
|
||||
Sends a string response with status code.
|
||||
|
||||
### File
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user