-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.11 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
package main
import (
"database/sql"
"fmt"
"os"
"github.com/aria3ppp/url-shortener/helper"
"github.com/aria3ppp/url-shortener/internal/core/usecase"
"github.com/aria3ppp/url-shortener/internal/generator"
"github.com/aria3ppp/url-shortener/internal/handler"
"github.com/aria3ppp/url-shortener/internal/repository"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
_ "github.com/lib/pq"
)
func main() {
dsn := fmt.Sprintf(
"postgres://%s:%s@%s:5432/%s?sslmode=disable",
os.Getenv("POSTGRES_USER"),
os.Getenv("POSTGRES_PASSWORD"),
os.Getenv("POSTGRES_HOST"),
os.Getenv("POSTGRES_DB"),
)
db, err := sql.Open("postgres", dsn)
if err != nil {
panic(err)
}
if err := db.Ping(); err != nil {
panic(err)
}
repo := repository.NewRepository(db)
generator := generator.NewRandomStringGenerator(6)
serviceUseCases := usecase.NewService(repo, generator)
handler := handler.NewHandler(serviceUseCases)
router := echo.New()
helper.HandleRoutes(router, handler)
router.Use(middleware.Logger())
if err := router.Start(":" + os.Getenv("SERVER_PORT")); err != nil {
panic(err)
}
}