feat: migrate Flask API to Go with JWT auth
This commit is contained in:
16
pkg/utils/utils.go
Normal file
16
pkg/utils/utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func JSONResponse(w http.ResponseWriter, code int, payload interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
json.NewEncoder(w).Encode(payload)
|
||||
}
|
||||
|
||||
func JSONError(w http.ResponseWriter, code int, message string) {
|
||||
JSONResponse(w, code, map[string]string{"error": message})
|
||||
}
|
||||
Reference in New Issue
Block a user