Add context support to Server.createUser

This commit is contained in:
Simon Ser 2021-11-08 20:29:14 +01:00
parent e3b1930bf2
commit d870efa666
2 changed files with 3 additions and 3 deletions

View File

@ -124,7 +124,7 @@ func (s *Server) Shutdown() {
} }
} }
func (s *Server) createUser(user *User) (*user, error) { func (s *Server) createUser(ctx context.Context, user *User) (*user, error) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
@ -132,7 +132,7 @@ func (s *Server) createUser(user *User) (*user, error) {
return nil, fmt.Errorf("user %q already exists", user.Username) return nil, fmt.Errorf("user %q already exists", user.Username)
} }
err := s.db.StoreUser(context.TODO(), user) err := s.db.StoreUser(ctx, user)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not create user in db: %v", err) return nil, fmt.Errorf("could not create user in db: %v", err)
} }

View File

@ -758,7 +758,7 @@ func handleUserCreate(ctx context.Context, dc *downstreamConn, params []string)
Realname: *realname, Realname: *realname,
Admin: *admin, Admin: *admin,
} }
if _, err := dc.srv.createUser(user); err != nil { if _, err := dc.srv.createUser(ctx, user); err != nil {
return fmt.Errorf("could not create user: %v", err) return fmt.Errorf("could not create user: %v", err)
} }