forked from telematum/screening
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
29 lines (27 loc) · 930 Bytes
/
api.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
package main
import (
"fmt"
"net/http"
)
func setupJsonApi() {
http.HandleFunc("/createUser", func(w http.ResponseWriter, r *http.Request) {
// create mysql connection
conn := createConnection()
name := r.FormValue("name")
email := r.FormValue("email")
query := "INSERT INTO users (name, email) VALUES (" + name + ", " + email + ")"
result, err := conn.Exec(query)
fmt.Println("result ", result, " err ", err.Error())
w.Write([]byte("Created user successfully!"))
})
http.HandleFunc("/updateUser", func(w http.ResponseWriter, r *http.Request) {
// create mysql connection
conn := createConnection()
name := r.FormValue("name")
email := r.FormValue("email")
query := "Update users set name=" + name + ", email=" + email + " where id=" + r.FormValue("id")
result, err := conn.Exec(query)
fmt.Println("result ", result, " err ", err.Error())
w.Write([]byte("User updated successfully!"))
})
}