func (s *Session) Logout(ctx context.Context) error {
	tok := s.engine.session.Token()

	if tok == "" {
		return &apitypes.Error{
			Type: apitypes.UnauthorizedError,
			Err:  []string{"You must be logged in, to logout!"},
		}
	}

	err := s.engine.client.Tokens.Delete(ctx, tok)
	switch err := err.(type) {
	case *apitypes.Error:
		switch {
		case err.StatusCode >= 500:
			// On a 5XX response, we don't know for sure that the server
			// has successfully removed the auth token. Keep the copy in
			// the daemon, so the user may try again.
			return err
		case err.StatusCode >= 400:
			// A 4XX error indicates either the token isn't found, or we're
			// not allowed to remove it (or the server is a teapot).
			//
			// In any case, the daemon has gotten out of sync with the
			// server. Remove our local copy of the auth token.
			log.Printf("Got 4XX removing auth token. Treating as success")
			logoutErr := s.engine.session.Logout()
			if logoutErr != nil {
				return logoutErr
			}

			return nil
		}
	case nil:
		logoutErr := s.engine.session.Logout()
		if logoutErr != nil {
			return logoutErr
		}

		return nil
	default:
		return err
	}

	return nil
}
// Logout destroys the current session if it exists, otherwise, it returns an
// error that the request could not be completed.
Logout destroys the current session if it exists, otherwise, it returns an
error that the request could not be completed.
// Logout destroys the current session if it exists otherwise it returns an // error that the request could not be completed .
func (s *Session) Logout(ctx context.Context) error {
	tok := s.engine.session.Token()
	if tok == "" {
		return &apitypes.Error{
			Type: apitypes.UnauthorizedError,
			Err:  []string{"You must be logged in, to logout!"},
		}
	}
	err := s.engine.client.Tokens.Delete(ctx, tok)
	switch err := err.(type) {
	case *apitypes.Error:
		switch {
		case err.StatusCode >= 500:
			return err
		case err.StatusCode >= 400:
			 In any case, the daemon has gotten out of sync with the
			 server. Remove our local copy of the auth token.
			log.Printf("Got 4XX removing auth token. Treating as success")
			logoutErr := s.engine.session.Logout()
			if logoutErr != nil {
				return logoutErr
			}
			return nil
		}
	case nil:
		logoutErr := s.engine.session.Logout()
		if logoutErr != nil {
			return logoutErr
		}
		return nil
	default:
		return err
	}
	return nil
}
func ( s * Session ) Logout ( ctx context . Context ) error { tok := s . engine . session . Token ( ) if tok == " " { return & apitypes . Error { Type : apitypes . UnauthorizedError , Err : [ ] string { " " } , } } err := s . engine . client . Tokens . Delete ( ctx , tok ) switch err := err . ( type ) { case * apitypes . Error : switch { case err . StatusCode >= 500 : return err case err . StatusCode >= 400 : log . Printf ( " " ) logoutErr := s . engine . session . Logout ( ) if logoutErr != nil { return logoutErr } return nil } case nil : logoutErr := s . engine . session . Logout ( ) if logoutErr != nil { return logoutErr } return nil default : return err } return nil }
Logout destroys the current session if it exists, otherwise, it returns an
error that the request could not be completed.
Logout destroys the current session if it exists otherwise it returns an error that the request could not be completed .
// On a 5XX response, we don't know for sure that the server // has successfully removed the auth token. Keep the copy in // the daemon, so the user may try again. // A 4XX error indicates either the token isn't found, or we're // not allowed to remove it (or the server is a teapot). // // In any case, the daemon has gotten out of sync with the // server. Remove our local copy of the auth token.