-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (37 loc) · 1.02 KB
/
main.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
44
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
)
func main() {
http.HandleFunc("/register", func(w http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
b, err := ioutil.ReadAll(req.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read request from client: %s\n", err)
w.WriteHeader(500)
fmt.Fprintf(w, `{"error":"failed"}`)
return
}
var in struct {
Email string `json:"email"`
}
if err := json.Unmarshal(b, &in); err != nil {
fmt.Fprintf(os.Stderr, "failed to parse request '%s' from client: %s\n", string(b), err)
w.WriteHeader(500)
fmt.Fprintf(w, `{"error":"failed"}`)
return
}
fmt.Printf("[%s] REGISTER <%s>\n", time.Now().Format(time.RFC3339), in.Email)
w.WriteHeader(200)
fmt.Fprintf(w, `{"ok":"registered"}`)
})
http.Handle("/", http.FileServer(http.Dir("./htdocs")))
fmt.Fprintf(os.Stderr, "coming-soon listening on *:3000...\n")
http.ListenAndServe(":3000", nil)
fmt.Fprintf(os.Stderr, "coming-soon shutting down...\n")
}