-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (31 loc) · 930 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
package main
import (
"database/sql"
"html/template"
"log"
"net/http"
_ "github.com/go-sql-driver/mysql"
)
var templates = template.Must(template.ParseFiles("template/login.html"))
func createLoginRender(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Println("AAA" + r.FormValue("password"))
log.Println("BBB" + r.FormValue("user_name"))
handleError(w, templates.ExecuteTemplate(w, "login", nil))
}
}
func handleError(w http.ResponseWriter, err error) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func main() {
db, err := sql.Open("mysql", "ibs:admin@tcp(127.0.0.1:3306)/ibs_login")
if err != nil {
log.Fatal(err)
}
defer db.Close()
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("template/css"))))
http.HandleFunc("/login", createLoginRender(db))
log.Fatal(http.ListenAndServe(":3001", nil))
}