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: dashboard.go
    path of file: ./repos/goatcounter/cmd/goatcounter
    
    the code of the file until where you have to start completion: // Copyright © Martin Tournoij – This file is part of GoatCounter and published
// under the terms of a slightly modified EUPL v1.2 license, which can be found
// in the LICENSE file or at https://license.goatcounter.com

package main

import (
	"encoding/json"
	"fmt"
	"io"
	"math"
	"net/http"
	"os"
	"strconv"
	"strings"
	"time"

	"zgo.at/errors"
	"zgo.at/goatcounter/v2"
	"zgo.at/termtext"
	"zgo.at/zli"
	"zgo.at/zstd/zint"
	"zgo.at/zstd/zstring"
	"zgo.at/zstd/ztime"
)

const usageDashboard = `
View the dashboard of a GoatCounter installation via the API.

This requires an API key with the "read sites" and "read statistics"

    
func parseRange(rangeFlag string) (ztime.Range, error) {
	var (
		now = ztime.Time{ztime.Now()}
		// Default to last week.
		rng = ztime.NewRange(now.AddPeriod(-7, ztime.Day).Time).To(now.Time)
	)

	// No flag: return default.
	if rangeFlag == "" {
		return rng, nil
	}

	// -range 30 for last 30 days.
	n, err := strconv.ParseInt(rangeFlag, 0, 64)
	if err == nil {
		rng.Start = now.AddPeriod(int(-n), ztime.Day).Time
		return rng, nil
	}

	// Parse explicit dates as "2006-01-02:2006-01-02"
	startFlag, endFlag, ok := strings.Cut(rangeFlag, ":")
	if !ok {
		return rng, fmt.Errorf("unknown format for -range: %q", rangeFlag)
	}

	rng.Start, err = time.Parse("2006-01-02", startFlag)
	if err != nil {
		return rng, fmt.Errorf("unknown format for -range: %q", rangeFlag)
	}
	rng.End, err = time.Parse("2006-01-02", endFlag)
	if err != nil {
		return rng, fmt.Errorf("unknown format for -range: %q", rangeFlag)
	}
	rng.End = ztime.EndOf(rng.End, ztime.Day)

	return rng, nil
}