Created
November 2, 2019 14:10
-
-
Save syahrul12345/551aeca787e120ab39b7670f4a6fb88e to your computer and use it in GitHub Desktop.
Lightweight utils module to send back response to client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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