Brijesh's Git Server — toolkit @ 07f7705d52a615e47c3440f848a64abd85da22b1

my attempt at building my own web framework so I feel more confident when using chi

router/send_json.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
package router

import (
	"encoding/json"
	"net/http"
)

func SendResponse(w http.ResponseWriter, status int, response interface{}) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(status)
	json.NewEncoder(w).Encode(response)
}