Use DB context

This commit is contained in:
Daniel 2024-10-21 14:11:08 -04:00
parent e29c3180b9
commit b3693522ae
4 changed files with 7 additions and 7 deletions

View file

@ -132,7 +132,7 @@ func addUserCommand(cfg *config.Config) *cobra.Command {
Use: "add",
Short: "adds a user",
RunE: func(cmd *cobra.Command, args []string) error {
db, err := database.NewClient(cfg.DB)
db, err := database.NewClient(context.Background(), cfg.DB)
if err != nil {
return err
}
@ -163,7 +163,7 @@ func passwdCommand(cfg *config.Config) *cobra.Command {
Short: "changes password for a user",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
db, err := database.NewClient(cfg.DB)
db, err := database.NewClient(context.Background(), cfg.DB)
if err != nil {
return err
}

View file

@ -22,7 +22,7 @@ type DB struct {
}
// NewClient creates a new DB using the provided config.
func NewClient(conf config.DB) (*DB, error) {
func NewClient(ctx context.Context, conf config.DB) (*DB, error) {
dir, err := iofs.New(sqlembed.Migrations, "postgres/migrations")
if err != nil {
return nil, err
@ -40,7 +40,7 @@ func NewClient(conf config.DB) (*DB, error) {
m.Close()
pool, err := pgxpool.New(context.Background(), conf.Connect)
pool, err := pgxpool.New(ctx, conf.Connect)
if err != nil {
return nil, err
}

View file

@ -58,7 +58,7 @@ func (o *ServeOptions) Execute() error {
}
}()
srv, err := server.New(o.cfg)
srv, err := server.New(ctx, o.cfg)
if err != nil {
return err
}

View file

@ -30,13 +30,13 @@ type Server struct {
logger *Logger
}
func New(cfg *config.Config) (*Server, error) {
func New(ctx context.Context, cfg *config.Config) (*Server, error) {
logger, err := NewLogger(cfg)
if err != nil {
return nil, err
}
db, err := database.NewClient(cfg.DB)
db, err := database.NewClient(ctx, cfg.DB)
if err != nil {
return nil, err
}