Use DB context
This commit is contained in:
parent
e29c3180b9
commit
b3693522ae
4 changed files with 7 additions and 7 deletions
|
@ -132,7 +132,7 @@ func addUserCommand(cfg *config.Config) *cobra.Command {
|
||||||
Use: "add",
|
Use: "add",
|
||||||
Short: "adds a user",
|
Short: "adds a user",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func passwdCommand(cfg *config.Config) *cobra.Command {
|
||||||
Short: "changes password for a user",
|
Short: "changes password for a user",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type DB struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new DB using the provided config.
|
// 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")
|
dir, err := iofs.New(sqlembed.Migrations, "postgres/migrations")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -40,7 +40,7 @@ func NewClient(conf config.DB) (*DB, error) {
|
||||||
|
|
||||||
m.Close()
|
m.Close()
|
||||||
|
|
||||||
pool, err := pgxpool.New(context.Background(), conf.Connect)
|
pool, err := pgxpool.New(ctx, conf.Connect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ type Server struct {
|
||||||
logger *Logger
|
logger *Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *config.Config) (*Server, error) {
|
func New(ctx context.Context, cfg *config.Config) (*Server, error) {
|
||||||
logger, err := NewLogger(cfg)
|
logger, err := NewLogger(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := database.NewClient(cfg.DB)
|
db, err := database.NewClient(ctx, cfg.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue