1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-12 10:02:48 +00:00

convert to chi web framework - add tls support

This commit is contained in:
2017-07-20 21:34:36 -05:00
parent b915ec065a
commit 4baad6b025
6 changed files with 178 additions and 62 deletions

View File

@@ -0,0 +1,32 @@
package response
import (
"encoding/json"
"net/http"
)
var (
DefaultUnauthorized = []byte("Unauthorized.")
DefaultInternalError = []byte("Internal error.")
)
// JSON - marshals the provided interface and returns JSON to client
func JSON(w http.ResponseWriter, content interface{}) {
output, err := json.Marshal(content)
if err != nil {
ERR(w, http.StatusInternalServerError, []byte("Internal error."))
return
}
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
}
// ERR - send error response
func ERR(w http.ResponseWriter, status int, content []byte) {
w.WriteHeader(status)
w.Write(content)
}