forked from Alexey/DAS_2024_1
48 lines
884 B
Go
48 lines
884 B
Go
package main
|
|
|
|
import (
|
|
"PersonApp/handlers"
|
|
"PersonApp/httpClient"
|
|
"PersonApp/repository"
|
|
"PersonApp/storage"
|
|
"github.com/gorilla/mux"
|
|
"github.com/joho/godotenv"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
err := godotenv.Load(".env")
|
|
if err != nil {
|
|
panic("Error loading .env file")
|
|
}
|
|
|
|
url := os.Getenv("TASK_APP_URL")
|
|
port := os.Getenv("PORT")
|
|
databasePath := os.Getenv("DATABASE")
|
|
timeout, err := strconv.Atoi(os.Getenv("TIMEOUT"))
|
|
|
|
if err != nil {
|
|
panic("Error converting timeout to int")
|
|
}
|
|
|
|
database, err := storage.Init(databasePath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
cln := httpClient.NewClient(url, time.Duration(timeout))
|
|
rep := repository.NewPersonRepository(database)
|
|
router := mux.NewRouter()
|
|
handlers.InitRoutes(router, rep, cln)
|
|
|
|
err = http.ListenAndServe(":"+port, router)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
storage.Close(database)
|
|
}
|