Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"
"time"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/joho/godotenv"
"github.com/resend/resend-go/v3"
"github.com/stripe/stripe-go/v86"
Expand All @@ -28,7 +28,7 @@ type config struct {

type application struct {
config config
db *pgx.Conn
db *pgxpool.Pool
resend *resend.Client
stripe *stripe.Client
cache *cache.RedisCache
Expand All @@ -53,11 +53,15 @@ func main() {

ctx := context.Background()

conn, pgErr := pgx.Connect(ctx, cfg.db.dsn)
if pgErr != nil {
panic(pgErr)
dbpool, poolErr := pgxpool.New(ctx, cfg.db.dsn)
if poolErr != nil {
panic(poolErr)
}
defer dbpool.Close()

if err := dbpool.Ping(ctx); err != nil {
panic(err)
}
defer conn.Close(ctx)

log.Println("Database connected successfully")

Expand All @@ -76,7 +80,7 @@ func main() {

app := &application{
config: cfg,
db: conn,
db: dbpool,
resend: client,
stripe: sc,
cache: redisCache,
Expand Down
6 changes: 3 additions & 3 deletions internal/auth/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
codeerror "gin-api-1/internal/codeerror"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

type Service interface {
Expand All @@ -26,10 +26,10 @@ type authRepository interface {

type svc struct {
repo authRepository
db *pgx.Conn
db *pgxpool.Pool
}

func NewAuthService(repo authRepository, db *pgx.Conn) Service {
func NewAuthService(repo authRepository, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
5 changes: 3 additions & 2 deletions internal/integrations/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

var repositoryPattern = regexp.MustCompile(`^[A-Za-z0-9-_.]+/[A-Za-z0-9-_.]+$`)
Expand All @@ -30,11 +31,11 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
github *gitHubClient
}

func NewIntegrationsService(repo *repo.Queries, db *pgx.Conn) Service {
func NewIntegrationsService(repo *repo.Queries, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions internal/messages/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"gin-api-1/internal/codeerror"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

type Service interface {
Expand All @@ -23,10 +23,10 @@ type messagesRepository interface {

type svc struct {
repo messagesRepository
db *pgx.Conn
db *pgxpool.Pool
}

func NewMessagesService(repo messagesRepository, db *pgx.Conn) Service {
func NewMessagesService(repo messagesRepository, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
5 changes: 3 additions & 2 deletions internal/projects/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

type Service interface {
Expand All @@ -23,10 +24,10 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
}

func NewProjectsService(repo *repo.Queries, db *pgx.Conn) Service {
func NewProjectsService(repo *repo.Queries, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions internal/subscriptions/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"gin-api-1/internal/codeerror"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stripe/stripe-go/v86"
)

Expand All @@ -21,11 +21,11 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
client *stripe.Client
}

func NewSubscriptionsService(repo *repo.Queries, db *pgx.Conn, client *stripe.Client) Service {
func NewSubscriptionsService(repo *repo.Queries, db *pgxpool.Pool, client *stripe.Client) Service {
return &svc{
repo: repo,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions internal/tasks/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

const dateLayout = "2006-01-02"
Expand All @@ -23,10 +23,10 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
}

func NewTasksService(repo *repo.Queries, db *pgx.Conn) Service {
func NewTasksService(repo *repo.Queries, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
5 changes: 3 additions & 2 deletions internal/workspace/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stripe/stripe-go/v86"
)

Expand All @@ -25,11 +26,11 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
stripe payment.Svc
}

func NewWorkspaceService(repo *repo.Queries, db *pgx.Conn, stripe payment.Svc) Service {
func NewWorkspaceService(repo *repo.Queries, db *pgxpool.Pool, stripe payment.Svc) Service {
return &svc{
repo: repo,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions internal/workspacemembers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
codeerror "gin-api-1/internal/codeerror"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)

type Service interface {
Expand All @@ -18,10 +18,10 @@ type Service interface {

type svc struct {
repo *repo.Queries
db *pgx.Conn
db *pgxpool.Pool
}

func NewWorkspaceMembersService(repo *repo.Queries, db *pgx.Conn) Service {
func NewWorkspaceMembersService(repo *repo.Queries, db *pgxpool.Pool) Service {
return &svc{
repo: repo,
db: db,
Expand Down
Loading