initial commit
This commit is contained in:
38
responses.go
Normal file
38
responses.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package stdmodels
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"gitlab.com/developerdurp/logger"
|
||||
)
|
||||
|
||||
func FailureReponse(message string, w http.ResponseWriter, statusCode int, description []string) {
|
||||
response := StandardError{
|
||||
Message: message,
|
||||
Status: statusCode,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
w.WriteHeader(statusCode)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
err := json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
logger.LogError("Failed to Encode")
|
||||
}
|
||||
}
|
||||
|
||||
func SuccessResponse(message string, w http.ResponseWriter, statusCode int) {
|
||||
response := StandardMessage{
|
||||
Message: message,
|
||||
}
|
||||
|
||||
w.WriteHeader(statusCode)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
err := json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
logger.LogError("Failed to Encode")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user