fix the errors in this golang code:

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"path/filepath"
	"strings"
	"time"

	"github.com/gdamore/tcell/v2"
	"github.com/pkg/sftp"
	"github.com/rivo/tview"
	"golang.org/x/crypto/ssh"
)

type FileSystem struct {
	currentPath string
	list        *tview.List
	isRemote    bool
	sftpClient  *sftp.Client
}

func NewFileSystem(isRemote bool, sftpClient *sftp.Client) *FileSystem {
	fs := &FileSystem{
		currentPath: "/",
		list:        tview.NewList().ShowSecondaryText(false),
		isRemote:    isRemote,
		sftpClient:  sftpClient,
	}
	fs.list.SetBorder(true).SetTitle(fmt.Sprintf("%s File System", getSystemType(isRemote)))
	return fs
}

func getSystemType(isRemote bool) string {
	if isRemote {
		return "Remote"
	}
	return "Local"
}

func (fs *FileSystem) updateList() {
	fs.list.Clear()
	fs.list.AddItem("[::b]📁 ..[-:-:-]", "Go to parent directory", 0, nil)

	if fs.isRemote {
		files, err := fs.sftpClient.ReadDir(fs.currentPath)
		if err != nil {
			log.Printf("Error reading remote directory: %v", err)
			return
		}
		for _, file := range files {
			addFileItem(fs.list, file.Name(), file.IsDir(), file.Mode()&os.ModeSymlink != 0)
		}
	} else {
		entries, err := os.ReadDir(fs.currentPath)
		if err != nil {
			log.Printf("Error reading local directory: %v", err)
			return
		}
		for _, entry := range entries {
			info, err := entry.Info()
			if err != nil {
				log.Printf("Error getting file info: %v", err)
				continue
			}
			addFileItem(fs.list, entry.Name(), entry.IsDir(), info.Mode()&os.ModeSymlink != 0)
		}
	}
}

func addFileItem(list *tview.List, name string, isDir bool, isSymlink bool) {
	var icon string
	var colorTag string
	if isSymlink {
		icon = "🔗"
		colorTag = "[yellow]"
	} else if isDir {
		icon = "📁"
		colorTag = "[blue]"
	} else {
		icon = "📄"
		colorTag = "[white]"
	}
	list.AddItem(fmt.Sprintf("%s%s %s[-]", colorTag, icon, name), "", 0, nil)
}

func (fs *FileSystem) navigateTo(path string) {
	fs.currentPath = path
	fs.updateList()
}

func createSFTPClient(host, user, password string) (*sftp.Client, error) {
	config := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.Password(password),
		},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	}

	conn, err := ssh.Dial("tcp", host, config)
	if err != nil {
		return nil, fmt.Errorf("failed to dial: %v", err)
	}

	client, err := sftp.NewClient(conn)
	if err != nil {
		return nil, fmt.Errorf("failed to create SFTP client: %v", err)
	}

	return client, nil
}

func transferFile(sourceFS, targetFS *FileSystem, filename string, progressBar *tview.TextView) {
	sourcePath := filepath.Join(sourceFS.currentPath, filename)
	targetPath := filepath.Join(targetFS.currentPath, filename)

	var sourceFile io.ReadCloser
	var targetFile io.WriteCloser
	var err error
	var fileSize int64

	// Open source file
	if sourceFS.isRemote {
		sourceFile, err = sourceFS.sftpClient.Open(sourcePath)
		if err == nil {
			fileInfo, err := sourceFS.sftpClient.Stat(sourcePath)
			if err == nil {
				fileSize = fileInfo.Size()
			}
		}
	} else {
		sourceFile, err = os.Open(sourcePath)
		if err == nil {
			fileInfo, err := os.Stat(sourcePath)
			if err == nil {
				fileSize = fileInfo.Size()
			}
		}
	}
	if err != nil {
		log.Printf("Error opening source file: %v", err)
		updateProgressBar(progressBar, fmt.Sprintf("Error opening source file: %v", err), 0)
		return
	}
	defer sourceFile.Close()

	// Create target file
	if targetFS.isRemote {
		targetFile, err = targetFS.sftpClient.Create(targetPath)
	} else {
		targetFile, err = os.Create(targetPath)
	}
	if err != nil {
		log.Printf("Error creating target file: %v", err)
		updateProgressBar(progressBar, fmt.Sprintf("Error creating target file: %v", err), 0)
		return
	}
	defer targetFile.Close()

	// Perform file transfer
	if sourceFS.isRemote {
		updateProgressBar(progressBar, "Downloading file...", 0)
	} else {
		updateProgressBar(progressBar, "Uploading file...", 0)
	}

	buf := make([]byte, 32*1024)
	var totalWritten int64
	for {
		n, err := sourceFile.Read(buf)
		if err != nil && err != io.EOF {
			log.Printf("Error reading from source: %v", err)
			updateProgressBar(progressBar, fmt.Sprintf("Error reading from source: %v", err), 0)
			return
		}
		if n == 0 {
			break
		}

		if _, err := targetFile.Write(buf[:n]); err != nil {
			log.Printf("Error writing to target: %v", err)
			updateProgressBar(progressBar, fmt.Sprintf("Error writing to target: %v", err), 0)
			return
		}
		totalWritten += int64(n)

		if fileSize > 0 {
			progress := float64(totalWritten) / float64(fileSize) * 100
			updateProgressBar(progressBar, fmt.Sprintf("Transferring... %.2f%%", progress), int(progress))
		}
	}

	updateProgressBar(progressBar, "Transfer completed successfully", 100)

	// Update file lists after transfer
	sourceFS.updateList()
	targetFS.updateList()
}

func updateProgressBar(progressBar *tview.TextView, message string, percent int) {
	progressBar.Clear()
	width := 50 // width of the progress bar
	completed := width * percent / 100
	if completed > width {
		completed = width
	}
	progressBar.SetText(fmt.Sprintf("%s\n[green]%s[white]%s",
		message,
		strings.Repeat("█", completed),
		strings.Repeat("░", width-completed)))
}

func main() {
	// SFTP server credentials
	host := "your_sftp_server:22"
	user := "your_username"
	password := "your_password"

	sftpClient, err := createSFTPClient(host, user, password)
	if err != nil {
		log.Fatalf("Failed to create SFTP client: %v", err)
	}
	defer sftpClient.Close()

	app := tview.NewApplication()
	localFS := NewFileSystem(false, nil)
	remoteFS := NewFileSystem(true, sftpClient)

	flex := tview.NewFlex().
		AddItem(localFS.list, 0, 1, true).
		AddItem(remoteFS.list, 0, 1, false)

	progressBar := tview.NewTextView().
		SetDynamicColors(true).
		SetRegions(true).
		SetWrap(false)

	progressBox := tview.NewBox().
		SetBorder(true).
		SetTitle("Transfer Progress")
	progressFlex := tview.NewFlex().
		AddItem(nil, 0, 1, false).
		AddItem(progressBar, 0, 3, false).
		AddItem(nil, 0, 1, false)

	mainFlex := tview.NewFlex().
		SetDirection(tview.FlexRow).
		AddItem(flex, 0, 1, true).
		AddItem(progressBox, 3, 1, false)

	progressBox.SetDrawFunc(func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
		progressFlex.SetRect(x, y, width, height)
		progressFlex.Draw(screen)
		return x, y, width, height
	})

	localFS.updateList()
	remoteFS.updateList()

	lastClickTime := time.Now()
	lastClickItem := -1

	handleItemSelection := func(currentFS, targetFS *FileSystem, index int) {
		if index == 0 {
			// Navigate to parent directory
			parentDir := filepath.Dir(currentFS.currentPath)
			currentFS.navigateTo(parentDir)
			return
		}

		selectedText, _ := currentFS.list.GetItemText(index)
		selectedPath := strings.TrimSpace(strings.TrimLeft(selectedText, "📁📄🔗 "))
		fullPath := filepath.Join(currentFS.currentPath, selectedPath)

		var isDir bool
		if currentFS.isRemote {
			info, err := currentFS.sftpClient.Stat(fullPath)
			if err != nil {
				log.Printf("Error getting remote file info: %v", err)
				return
			}
			isDir = info.IsDir()
		} else {
			info, err := os.Stat(fullPath)
			if err != nil {
				log.Printf("Error getting local file info: %v", err)
				return
			}
			isDir = info.IsDir()
		}

		if isDir {
			currentFS.navigateTo(fullPath)
		} else {
			go transferFile(currentFS, targetFS, selectedPath, progressBar)
		}
	}

	app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyTab:
			if app.GetFocus() == localFS.list {
				app.SetFocus(remoteFS.list)
			} else {
				app.SetFocus(localFS.list)
			}
			return nil
		case tcell.KeyEnter:
			currentList := app.GetFocus().(*tview.List)
			currentFS := localFS
			targetFS := remoteFS
			if currentList == remoteFS.list {
				currentFS = remoteFS
				targetFS = localFS
			}

			selectedItem := currentList.GetCurrentItem()
			handleItemSelection(currentFS, targetFS, selectedItem)
			return nil
		}
		return event
	})

	app.SetMouseCapture(func(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) {
		if action == tview.MouseLeftClick {
			x, y := event.Position()
			var currentFS, targetFS *FileSystem
			var currentList *tview.List

			if x < app.GetScreen().Size()/2 {
				currentFS = localFS
				targetFS = remoteFS
				currentList = localFS.list
			} else {
				currentFS = remoteFS
				targetFS = localFS
				currentList = remoteFS.list
			}

			_, _, _, height := currentList.GetRect()
			index := y - 1 // Adjust for the border

			if index >= 0 && index < currentList.GetItemCount() {
				if index == lastClickItem && time.Since(lastClickTime) < 400*time.Millisecond {
					// Double click detected
					handleItemSelection(currentFS, targetFS, index)
				}
				lastClickItem = index
				lastClickTime = time.Now()
			}
		}
		return event, action
	})

	if err := app.SetRoot(mainFlex, true).EnableMouse(true).Run(); err != nil {
		log.Fatalf("Error running application: %v", err)
	}
}