50 lines
817 B
Go
50 lines
817 B
Go
package nf
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
type Ctx struct {
|
|
app *App
|
|
Response http.ResponseWriter
|
|
Request *http.Request
|
|
Path string
|
|
Method string
|
|
Params map[string]string
|
|
StatusCode int
|
|
}
|
|
|
|
func newCtx(a *App, w http.ResponseWriter, req *http.Request) *Ctx {
|
|
return &Ctx{
|
|
app: a,
|
|
Response: w,
|
|
Request: req,
|
|
Path: req.URL.Path,
|
|
Method: req.Method,
|
|
}
|
|
}
|
|
|
|
func (c *Ctx) Param(key string) string {
|
|
value, _ := c.Params[key]
|
|
return value
|
|
}
|
|
|
|
func (c *Ctx) Status(status int) *Ctx {
|
|
if c.StatusCode != 0 {
|
|
c.app.logger.Warn()
|
|
}
|
|
c.StatusCode = status
|
|
return c
|
|
}
|
|
|
|
func (c *Ctx) SendStatus(status int) error {
|
|
panic("impl this")
|
|
}
|
|
|
|
func (c *Ctx) SendString(value string) error {
|
|
_, err := c.Response.Write([]byte(value))
|
|
_ = err
|
|
return errors.New(value)
|
|
}
|