-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (33 loc) · 795 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
centralmux := http.NewServeMux()
centralmux.HandleFunc("/", handler)
err := http.ListenAndServe(":8080", centralmux)
if err != nil {
fmt.Println("Error", err)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
endpoint := r.URL.Path
switch endpoint {
case "/login":
handlerLogin(w, r)
case "/signup":
handlerSignup(w, r)
default:
http.NotFound(w, r)
}
}
func handlerLogin(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode("Info: User Login Info")
}
func handlerSignup(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode("Info: User Signup Info")
}