alpha
This commit is contained in:
parent
53e59ddf89
commit
079542e431
9 changed files with 191 additions and 57 deletions
|
@ -1,9 +1,27 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, data interface{}, code int) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
func WriteError(w http.ResponseWriter, message string, code int) {
|
||||
WriteJSON(w, Response{Code: code, Message: message}, code)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue