-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_users.go
43 lines (35 loc) · 869 Bytes
/
handle_users.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"encoding/json"
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
)
type User struct {
Email string `json:"email"`
Password string `json:"password"`
}
func HandleNewSession(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
decoder := json.NewDecoder(r.Body)
var u User
err := decoder.Decode(&u)
if err != nil {
panic(err)
}
defer r.Body.Close()
email := u.Email
password := u.Password
fmt.Printf("--> Received a POST to /login with %s and %s\n", email, password)
}
func HandleNewUser(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
decoder := json.NewDecoder(r.Body)
var u User
err := decoder.Decode(&u)
if err != nil {
panic(err)
}
defer r.Body.Close()
email := u.Email
password := u.Password
fmt.Printf("--> Received a POST to /signup with %s and %s\n", email, password)
}