Skip to content

Instantly share code, notes, and snippets.

@syahrul12345
Created November 2, 2019 14:10
Show Gist options
  • Save syahrul12345/551aeca787e120ab39b7670f4a6fb88e to your computer and use it in GitHub Desktop.
Save syahrul12345/551aeca787e120ab39b7670f4a6fb88e to your computer and use it in GitHub Desktop.
Lightweight utils module to send back response to client
package utils
import (
"encoding/json"
"net/http"
)
//Message outputs the message to be sent to the client
func Message(status bool, message string) map[string]interface{} {
return map[string]interface{}{
"status": status,
"message": message,
}
}
//Respond automatically writes to the HTTP response, and will be displayed for the frontend
func Respond(writer http.ResponseWriter, message map[string]interface{}) {
writer.Header().Add("Content-Type", "application/json")
json.NewEncoder(writer).Encode(message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment