add pathvalue and url query

This commit is contained in:
Pedro Pérez 2024-11-22 12:52:29 +01:00
parent 89afb56836
commit 554fb45e33

8
ron.go
View File

@ -239,6 +239,14 @@ func (e *Engine) Static(path, dir string) error {
return nil return nil
} }
func (c *CTX) Path(key string) string {
return c.R.PathValue(key)
}
func (c *CTX) Query(key string) string {
return c.R.URL.Query().Get(key)
}
func (c *CTX) JSON(code int, data any) { func (c *CTX) JSON(code int, data any) {
c.W.Header().Set("Content-Type", "application/json") c.W.Header().Set("Content-Type", "application/json")
encoder := json.NewEncoder(c.W) encoder := json.NewEncoder(c.W)