-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
119 lines (108 loc) · 3.18 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"anyone-server/database"
_ "anyone-server/database"
db "anyone-server/database"
fb "anyone-server/firebase"
route "anyone-server/route"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func rJson() {
plan, _ := ioutil.ReadFile("aa.json")
var data map[string]interface{}
json.Unmarshal(plan, &data)
log.Println(len(data["Row"].([]interface{})))
db := database.DB()
i := 1
for _, v := range data["Row"].([]interface{}) {
m := v.(map[string]interface{})
u := m["업종명"].(string)
if u == "음식점" || u == "술집" || u == "카페" {
cID := "1"
if u == "음식점" {
cID = "2"
}
if u == "술집" {
cID = "3"
}
name, _ := m["업소명"].(string)
address, ok := m["소재지_도로명_"].(string)
if !ok {
address = ""
}
phone, ok := m["소재지전화"].(string)
if !ok {
phone = ""
}
tSeat := fmt.Sprintf("%d", rand.Intn(30)+8)
query := "INSERT INTO store_info (category_id, lat, lng, name, total_seat, current_seat, phone_number, address, created_at, updated_at) " +
"VALUES (" + cID + ", '', '', '" + name + "', " + tSeat + ", 2, '" + phone + "', '" + address + "', NOW(), NOW());"
insert, err := db.Query(query)
if err != nil {
log.Println(err)
log.Println(query)
} else {
insert.Close()
}
log.Println("[" + fmt.Sprintf("%d", i) + "/4120]")
i++
}
}
}
func main() {
log.Println("Starting...")
// Load enviroment variables
err := godotenv.Load(".env.development")
if err != nil {
log.Println("Main:: cannot load .env.development file")
}
// Firebase
fb.InitFirebaseAdminSDK()
db.InitDatabase()
defer db.DB().Close()
// rJson()
// Creates a router without any middleware by default
r := gin.New()
// Global middleware
// Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release.
// By default gin.DefaultWriter = os.Stdout
r.Use(gin.Logger())
r.LoadHTMLGlob("templates/*")
// Recovery middleware recovers from any panics and writes a 500 if there was one.
r.Use(gin.Recovery())
router := r.Group("/")
{
router.POST("/store/info", route.GetStoreInfo)
router.POST("/store/seat/get", route.GetStoreCurrentSeat)
router.POST("/store/home", route.GetStoreHome)
router.POST("/review/insert", route.PutReview)
router.POST("/user/bookmark", route.GetBookmarks)
router.POST("/user/bookmark/put", route.PutBookmark)
router.POST("/user/search/history", route.GetSearchHistory)
router.POST("/store/search", route.GetSearchResult)
router.POST("/store/home/near", route.GetStoreNearLocation)
router.POST("/store/near", route.GetStoreNearLocation)
router.POST("/store/seat/put", route.PutStoreCurrentSeat)
router.POST("/store/seat/list/put", route.PutStoreCurrentSeatList)
router.GET("/input", route.InputLatLng)
router.POST("/input", route.Input)
}
// Authorization group
authorized := r.Group("/auth")
//authorized.Use(handlers.TokenAuthMiddleware())
{
authorized.GET("/ws", func(c *gin.Context) {
//wsHandler(c.Writer, c.Request, c.ClientIP())
// sockets.ServeWs(hub, c.Writer, c.Request)
})
}
port := os.Getenv("PORT")
r.Run(":" + port)
}