-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (35 loc) · 1 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
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/nozo-moto/search_engine/crawler"
"github.com/nozo-moto/search_engine/db"
"github.com/nozo-moto/search_engine/page"
"github.com/nozo-moto/search_engine/presenter/adapter"
)
type Server struct {
router *mux.Route
}
func main() {
router := mux.NewRouter()
dbx, err := db.ConnectToDatabase()
if err != nil {
panic(err)
}
defer dbx.Close()
pageAdapter := adapter.NewPageAdapter(
page.NewPageUseCase(
db.NewPageMySQLAdapter(dbx),
),
crawler.NewCrawleUseCase(
db.NewPageMySQLAdapter(dbx),
),
)
// query parameterで q=検索したい文字列 limit=検索数
router.Handle("/api/v1/page", handler(pageAdapter.GET)).Methods("GET")
// toppageを追加するuPI {url: "hwertyui.com"}
router.Handle("/api/v1/toppage", handler(pageAdapter.AddTopPage)).Methods("POST")
// Crawler を動かすendpoint
router.Handle("/api/v1/crawler", handler(pageAdapter.MoveCrawler)).Methods("GET")
http.ListenAndServe(":8080", router)
}