[feature] Merged with api-prototype
This commit is contained in:
45
cmd/main.go
45
cmd/main.go
@@ -1,7 +1,48 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"context"
|
||||
"git.pbiernat.dev/egommerce/application/services/identity/internal/app"
|
||||
"git.pbiernat.dev/egommerce/application/services/identity/internal/app/config"
|
||||
"git.pbiernat.dev/egommerce/application/services/identity/internal/app/database"
|
||||
"git.pbiernat.dev/egommerce/application/services/identity/internal/app/handler"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
defHttpIp = "127.0.0.1"
|
||||
defHttpPort = "8080"
|
||||
defDbUrl = "postgres://postgres:postgres@127.0.0.1:5432/egommerce" // FIXME: use env
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Identity services")
|
||||
if config.ErrLoadingEnvs != nil {
|
||||
app.Panicf("Error loading .env file")
|
||||
}
|
||||
|
||||
httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHttpIp), config.GetEnv("SERVER_PORT", defHttpPort))
|
||||
dbConnStr := config.GetEnv("DATABASE_URL", defDbUrl)
|
||||
|
||||
dbc, err := database.Connect(dbConnStr)
|
||||
if err != nil {
|
||||
app.Panicf("Unable to connect to database: %v\n", err)
|
||||
}
|
||||
|
||||
env := &handler.Env{httpAddr, dbc}
|
||||
srv := app.NewServer(env)
|
||||
|
||||
go srv.Start()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
<-c
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
srv.Shutdown(ctx)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user