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: crash_reporting.go
    path of file: ./repos/syncthing/cmd/syncthing
    
    the code of the file until where you have to start completion: // Copyright (C) 2019 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package main

import (
	"bytes"
	"context"
	"fmt"
	"net/http"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"time"

	"github.com/syncthing/syncthing/lib/sha256"
)

const (
	headRequestTimeout = 10 * time.Second
	putRequestTimeout  = time.Minute
)

// uploadPanicLogs attempts to upload all the panic logs in the named
// directory to the crash reporting server as urlBase. Uploads are attempted
// with the newest log first.
//
// This can can block for a long time. The context can set a final deadline
// for this.
func uploadPanicLogs(ctx context.Context, urlBase, dir string) {
	files, err := filepath.Glob(filepath.Join(dir, "panic-*.log"))
	if err != nil {
		l.Warnln("Failed to list panic logs:", err)
		return
	}

	sort.Sort(sort.Reverse(sort
    
func uploadPanicLog(ctx context.Context, urlBase, file string) error {
	data, err := os.ReadFile(file)
	if err != nil {
		return err
	}

	// Remove log lines, for privacy.
	data = filterLogLines(data)

	hash := fmt.Sprintf("%x", sha256.Sum256(data))
	l.Infof("Reporting crash found in %s (report ID %s) ...\n", filepath.Base(file), hash[:8])

	url := fmt.Sprintf("%s/%s", urlBase, hash)
	headReq, err := http.NewRequest(http.MethodHead, url, nil)
	if err != nil {
		return err
	}

	// Set a reasonable timeout on the HEAD request
	headCtx, headCancel := context.WithTimeout(ctx, headRequestTimeout)
	defer headCancel()
	headReq = headReq.WithContext(headCtx)

	resp, err := http.DefaultClient.Do(headReq)
	if err != nil {
		return err
	}
	resp.Body.Close()
	if resp.StatusCode == http.StatusOK {
		// It's known, we're done
		return nil
	}

	putReq, err := http.NewRequest(http.MethodPut, url, bytes.NewReader(data))
	if err != nil {
		return err
	}

	// Set a reasonable timeout on the PUT request
	putCtx, putCancel := context.WithTimeout(ctx, putRequestTimeout)
	defer putCancel()
	putReq = putReq.WithContext(putCtx)

	resp, err = http.DefaultClient.Do(putReq)
	if err != nil {
		return err
	}
	resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("upload: %s", resp.Status)
	}

	return nil
}