-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (45 loc) · 1.24 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
package main
import (
"log"
"net/http"
"github.com/BurntSushi/toml"
"github.com/elastic/go-elasticsearch/v7"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
"github.com/until-tsukuba/kdb2-server/internal/config"
"github.com/until-tsukuba/kdb2-server/internal/handler"
)
func main() {
config := new(config.Config)
if _, err := toml.DecodeFile("./config.toml", config); err != nil {
log.Fatalf("config load: %v\n", err)
return
}
h := new(handler.Handler)
cfg := &elasticsearch.Config{
Addresses: []string{config.ElasticSearchConfig.Host},
}
esclient, err := elasticsearch.NewClient(*cfg)
if err != nil {
log.Fatalf("esclient init: %v\n", err)
return
}
h.ESClient = esclient
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.RealIP)
r.Use(middleware.Recoverer)
r.Use(middleware.RequestID)
r.Use(cors.Handler(cors.Options{
AllowedHeaders: []string{"Accept", "Content-Type"},
AllowCredentials: false,
}))
r.Get("/", handler.Index)
r.Get("/result", h.Result)
r.Get("/api/v0/docs", handler.SwaggerUI)
r.Get("/api/v0/openapi", handler.OpenAPI)
r.Get("/api/v0/syllabus/{courseID}", h.SyllabusJSON)
r.Get("/api/v0/search", h.SimpleSearch)
http.ListenAndServe(":3030", r)
}