You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: wal_show_handler.go
    path of file: ./repos/wal-g/internal/databases/postgres/pgbackrest
    
    the code of the file until where you have to start completion: package pgbackrest

import (
	"path"
	"sort"
	"strings"

	"github.com/wal-g/tracelog"
	"github.com/wal-g/wal-g/internal/databases/postgres"
	"github.com/wal-g/wal-g/pkg/storages/storage"
)

func HandleWalShow(rootFolder storage.Folder, stanza string, outputWriter postgres.WalShowOutputWriter) error {
	archiveName, err := GetArchiveName(rootFolder, stanza)
	if err != nil {
		return err
	}

	archiveFolder := rootFolder.GetSubFolder(WalArchivePath).GetSubFolder(stanza).GetSubFolder(*archiveName)
	walFiles, err := getWalFiles(archiveFolder)
	if err != nil {
		return err
	}

	walSegments, err := getWalSegments(walFiles)
	if err != nil {
    
func HandleWalShow(rootFolder storage.Folder, stanza string, outputWriter postgres.WalShowOutputWriter) error {
	archiveName, err := GetArchiveName(rootFolder, stanza)
	if err != nil {
		return err
	}

	archiveFolder := rootFolder.GetSubFolder(WalArchivePath).GetSubFolder(stanza).GetSubFolder(*archiveName)
	walFiles, err := getWalFiles(archiveFolder)
	if err != nil {
		return err
	}

	walSegments, err := getWalSegments(walFiles)
	if err != nil {
		return err
	}
	walSequencesByTimelines := getWalSequencesByTimelines(walSegments)

	var timelineInfos []*postgres.TimelineInfo
	for _, segmentsSequence := range walSequencesByTimelines {
		historyRecords, err := postgres.GetTimeLineHistoryRecords(segmentsSequence.TimelineID, archiveFolder)
		if err != nil {
			if _, ok := err.(postgres.HistoryFileNotFoundError); !ok {
				tracelog.ErrorLogger.Fatalf("Error while loading .history file %v\n", err)
			}
		}

		info, err := postgres.NewTimelineInfo(segmentsSequence, historyRecords)
		tracelog.ErrorLogger.FatalfOnError("Error while creating TimeLineInfo %v\n", err)
		timelineInfos = append(timelineInfos, info)
	}

	sort.Slice(timelineInfos, func(i, j int) bool {
		return timelineInfos[i].ID < timelineInfos[j].ID
	})

	return outputWriter.Write(timelineInfos)
}