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
6 changes: 3 additions & 3 deletions internal/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package errors

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"go.uber.org/zap"
)

func ReturnError(err error) error {
Expand All @@ -28,8 +28,8 @@ func Return404(c *gin.Context) {
}

func RaiseInternalErr(c *gin.Context, err error) {
intErr := fmt.Errorf("%w: %w", ErrInternalError, err)
c.AbortWithStatusJSON(http.StatusInternalServerError, ReturnError(intErr))
zap.L().Error("internal server error", zap.Error(err))
c.AbortWithStatusJSON(http.StatusInternalServerError, ReturnError(ErrInternalError))
}

func RaiseBadRequestErr(c *gin.Context, err error) {
Expand Down
18 changes: 18 additions & 0 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import (
"github.com/stackmon/otc-status-dashboard/internal/event"
)

// Connection pool defaults.
const (
dbMaxOpenConns = 25
dbMaxIdleConns = 10
dbConnMaxLifetime = 5 * time.Minute
dbConnMaxIdleTime = 30 * time.Second
)

type DB struct {
g *gorm.DB
}
Expand All @@ -40,6 +48,16 @@ func New(c *conf.Config) (*DB, error) {
return nil, err
}

sqlDB, err := g.DB()
if err != nil {
return nil, fmt.Errorf("getting underlying sql.DB: %w", err)
}

sqlDB.SetMaxOpenConns(dbMaxOpenConns)
sqlDB.SetMaxIdleConns(dbMaxIdleConns)
sqlDB.SetConnMaxLifetime(dbConnMaxLifetime)
sqlDB.SetConnMaxIdleTime(dbConnMaxIdleTime)

return &DB{g: g}, nil
}

Expand Down
Loading