Login (#6)
Reviewed-on: phoenix/textsender-auth#6 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ExtractFromRequest(r *http.Request, reqItem interface{}) error {
|
||||
err := json.NewDecoder(r.Body).Decode(&reqItem)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func RespondWithJson(w http.ResponseWriter, statusCode int, data interface{}) {
|
||||
w.Header().Set("Content-type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
Reference in New Issue
Block a user