initial commit
This commit is contained in:
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module gitlab.com/developerdurp/stdmodels
|
||||||
|
|
||||||
|
go 1.22.0
|
||||||
|
|
||||||
|
require gitlab.com/developerdurp/logger v1.0.0 // indirect
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
gitlab.com/developerdurp/logger v1.0.0 h1:wozbKR26RVoFVaUgJV2x8WsZHLWOJBqaSCSTpK7crfk=
|
||||||
|
gitlab.com/developerdurp/logger v1.0.0/go.mod h1:x6gZvBeEq8oQUXeQoLY2m78mYJjvb5KE+7Vb5AcS8oo=
|
||||||
11
main.go
Normal file
11
main.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package stdmodels
|
||||||
|
|
||||||
|
type StandardMessage struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StandardError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
Description []string `json:"description"`
|
||||||
|
}
|
||||||
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