github.com/roblesoft/oak@v0.0.0-20230306162712-e6c5c487469e/ctx.go (about)

     1  package oak
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"net/http"
     7  )
     8  
     9  type Ctx struct {
    10  	Context  context.Context
    11  	response http.ResponseWriter
    12  	request  *http.Request
    13  }
    14  
    15  func (c *Ctx) JSON(data interface{}) error {
    16  	c.Response().Header().Set("Content-Type", "application/json")
    17  	return json.NewEncoder(c.Response()).Encode(data)
    18  }
    19  
    20  func (c *Ctx) Response() http.ResponseWriter {
    21  	return c.response
    22  }
    23  
    24  func (c *Ctx) Request() *http.Request {
    25  	return c.request
    26  }