-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
35 lines (28 loc) · 949 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/projects/hexagonal-architecture/api"
"github.com/projects/hexagonal-architecture/config"
"github.com/projects/hexagonal-architecture/domain"
"github.com/projects/hexagonal-architecture/repository"
)
func main() {
conf, _ := config.NewConfig("./config/config.yaml")
repo, _ := repository.NewMongoRepository(conf.Database.URL, conf.Database.DB, conf.Database.Timeout)
service := domain.NewProductService(repo)
handler := api.NewHandler(service)
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Get("/products/{code}", handler.Get)
r.Post("/products", handler.Post)
r.Delete("/products/{code}", handler.Delete)
r.Get("/products", handler.GetAll)
r.Put("/products", handler.Put)
log.Fatal(http.ListenAndServe(conf.Server.Port, r))
}