mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 14:26:58 +00:00
more string
This commit is contained in:
parent
662d76386c
commit
51ca74fc11
16 changed files with 121 additions and 123 deletions
|
@ -2,7 +2,9 @@ package context
|
|||
|
||||
import (
|
||||
stdContext "context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
|
@ -31,6 +33,19 @@ func (c *Context) Response() *http.Response {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) String(raw string, status ...int) {
|
||||
code := http.StatusOK
|
||||
if len(status) != 0 {
|
||||
code = status[0]
|
||||
}
|
||||
c.RespWriter.WriteHeader(code)
|
||||
io.Copy(c.RespWriter, strings.NewReader(raw))
|
||||
}
|
||||
|
||||
func (c *Context) IsMethod(m string) bool {
|
||||
return c.Req.Method == m
|
||||
}
|
||||
|
||||
func (c *Context) Redirect(uri string, statusCode int) {
|
||||
http.Redirect(c.RespWriter, c.Req, uri, statusCode)
|
||||
}
|
||||
|
@ -41,3 +56,7 @@ func (c *Context) Redirect(uri string, statusCode int) {
|
|||
func (c *Context) Path() string {
|
||||
return c.Req.URL.Path
|
||||
}
|
||||
|
||||
func (c *Context) Host() string {
|
||||
return c.Req.URL.Host
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue