github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/APIRestORM/handlers/response.go (about) 1 package handlers 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "net/http" 7 ) 8 9 func SendData(rw http.ResponseWriter, data interface{}, status int) { 10 rw.Header().Set("Content-Type", "application/json") 11 rw.WriteHeader(status) 12 13 output, _ := json.Marshal(&data) 14 fmt.Fprintln(rw, string(output)) 15 } 16 17 func sendError(rw http.ResponseWriter, status int) { 18 rw.Header().Set("Content-Type", "application/json") 19 fmt.Fprintln(rw, "Resource Not Found") 20 }