short/main.go

33 lines
691 B
Go
Raw Normal View History

2024-01-29 17:52:31 +00:00
package main
import (
"context"
"log"
"net/http"
"github.com/babariviere/short/internal/api"
"github.com/babariviere/short/internal/db"
"github.com/babariviere/short/internal/oas"
"github.com/jackc/pgx/v5"
)
2024-01-29 17:52:31 +00:00
func main() {
psql, err := pgx.Connect(context.Background(), "postgres://short:short@localhost:5432/short")
if err != nil {
log.Fatalf("cannot connect to database: %v", err)
}
queries := db.New(psql)
handler := api.NewHandler(queries)
srv, err := oas.NewServer(handler)
if err != nil {
log.Fatalf("failed te create OpenAPI server: %v", err)
}
log.Println("Listening on :8080")
if err = http.ListenAndServe(":8080", srv); err != nil {
log.Fatal(err)
}
2024-01-29 17:52:31 +00:00
}