-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 1.01 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 (
"database/sql"
"log"
"net/http"
"os"
"time"
"github.com/joeymhills/go-sql-api/handlers"
"github.com/patrickmn/go-cache"
_ "github.com/go-sql-driver/mysql"
)
func main() {
c := cache.New(10*time.Second, 1*time.Minute)
db, err := sql.Open("mysql", os.Getenv("DSN"))
if err != nil {
log.Fatal(err)
}
log.Println("DB connected and ready to serve🫡🫡🫡🫡🫡 ")
http.HandleFunc("/changerole", handlers.ChangeRole(db))
http.HandleFunc("/find", handlers.FindAward(db, c))
http.HandleFunc("/getusers", handlers.GetUsers(db))
http.HandleFunc("/getdeleted", handlers.GetDeleted(db))
http.HandleFunc("/search", handlers.SearchAwards(db))
http.HandleFunc("/recentawards", handlers.RecentAwards(db))
http.HandleFunc("/create", handlers.CreateAward(db, c))
http.HandleFunc("/update", handlers.UpdateAward(db, c))
port := os.Getenv("PORT")
if port == "" {
port = "3333"
}
http.ListenAndServe("0.0.0.0:"+port, nil)
log.Println("listening and serving")
}