code: func NewTerminal(req TerminalRequest, authProvider AuthProvider, ctx *SessionContext) (*TerminalHandler, error) {
  
  	// Make sure whatever session is requested is a valid session.
  	_, err := session.ParseID(string(req.SessionID))
  	if err != nil {
  		return nil, trace.BadParameter("sid: invalid session id")
  	}
  
  	if req.Login == "" {
  		return nil, trace.BadParameter("login: missing login")
  	}
  	if req.Term.W <= 0 || req.Term.H <= 0 {
  		return nil, trace.BadParameter("term: bad term dimensions")
  	}
  
  	servers, err := authProvider.GetNodes(req.Namespace, services.SkipValidation())
  	if err != nil {
  		return nil, trace.Wrap(err)
  	}
  
  	hostName, hostPort, err := resolveServerHostPort(req.Server, servers)
  	if err != nil {
  		return nil, trace.BadParameter("invalid server name %q: %v", req.Server, err)
  	}
  
  	return &TerminalHandler{
  		log: logrus.WithFields(logrus.Fields{
  			trace.Component: teleport.ComponentWebsocket,
  		}),
  		params:       req,
  		ctx:          ctx,
  		hostName:     hostName,
  		hostPort:     hostPort,
  		authProvider: authProvider,
  		encoder:      unicode.UTF8.NewEncoder(),
  		decoder:      unicode.UTF8.NewDecoder(),
  	}, nil
  }
docs: // NewTerminal creates a web-based terminal based on WebSockets and returns a
  // new TerminalHandler.