-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
55 lines (42 loc) · 1.08 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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"database/sql"
"log"
"net/http"
"github.com/fun-dev/auth-dev/auth"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
)
func signup(w http.ResponseWriter, r *http.Request) {
auth.Signup(w, r)
}
func login(w http.ResponseWriter, r *http.Request) {
auth.Login(w, r)
}
func removeAccount(w http.ResponseWriter, r *http.Request) {
auth.RemoveAccount(w, r)
}
var db *sql.DB
func main() {
db, err := sql.Open("mysql", auth.DBLocation())
if err != nil {
log.Println(err)
return
}
err = db.Ping()
if err != nil {
log.Println(err)
return
}
db.Close()
// urls.py
router := mux.NewRouter()
// endpoint
router.HandleFunc("/signup", signup).Methods("POST")
router.HandleFunc("/login", login).Methods("POST")
router.HandleFunc("/removeAccount", removeAccount).Methods("POST")
// console に出力する
log.Println("サーバー起動 : 8000 port で受信")
// log.Fatal は、異常を検知すると処理の実行を止めてくれる
log.Fatal(http.ListenAndServe(":8000", router))
}