-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 841 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
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"./driver"
handlerDomain "./handler/http"
"fmt"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"net/http"
"os"
)
const (
port = ":3000"
dbName = "testzofi_db"
dbHost = "localhost"
dbPort = "26257"
)
func main() {
connection, err := driver.ConnectSQL(dbHost, dbPort, dbName)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
router := chi.NewRouter()
router.Use(middleware.Recoverer)
router.Use(middleware.Logger)
handler := handlerDomain.NewDomainHandler(connection)
router.Route("/", func(rt chi.Router) {
rt.Mount("/domains", initRouter(handler))
})
http.ListenAndServe(port, router)
}
func initRouter(handler *handlerDomain.Domain) http.Handler {
router := chi.NewRouter()
router.Get("/", handler.GetS)
router.Get("/host={host}", handler.GetByHost)
return router
}