Skip to content

Commit 8ed3d34

Browse files
committed
Release 0.0.4
- Added minzoom parameter
1 parent 37b3474 commit 8ed3d34

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

main.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
"github.com/schollz/progressbar/v3"
3939
)
4040

41-
const version = "0.0.3"
41+
const version = "0.0.4"
4242

4343
var (
4444
headers headerFlags
@@ -62,6 +62,7 @@ func main() {
6262
// define command line flags
6363
url := flag.String("url", "", usageUrl)
6464
zoom := flag.Int("zoom", 4, usageZoom)
65+
minzoom := flag.Int("minzoom", 0, usageMinZoom)
6566
cc := flag.Int("cc", 4, usageCc)
6667
flag.Var(&headers, "header", usageHeader)
6768
help := flag.Bool("help", false, usageHelp)
@@ -73,19 +74,19 @@ func main() {
7374
}
7475

7576
// check the provided configuration
76-
checkConfig(*url, *zoom, *cc)
77+
checkConfig(*url, *zoom, *minzoom, *cc)
7778

7879
// run the primer
79-
prime(*url, *zoom, *cc, headers)
80+
prime(*url, *zoom, *minzoom, *cc, headers)
8081
}
8182

8283
// prime populates work queues, iteratively and concurrently priming the given
8384
// cache by requesting all tiles at every zoom level up to the one you specify
84-
func prime(url string, zoom, cc int, headers headerFlags) {
85+
func prime(url string, zoom, minzoom, cc int, headers headerFlags) {
8586
startPrime := time.Now()
8687

8788
// begin priming caches starting at zoom level 0
88-
for z := 0; z <= zoom; z++ {
89+
for z := minzoom; z <= zoom; z++ {
8990
startLevel := time.Now()
9091

9192
numTiles := int(math.Pow(float64(2), float64(2*z)))
@@ -257,7 +258,7 @@ func buildURL(url string, x, y, z int) string {
257258
}
258259

259260
// checkConfig ensures a proper configuration is provided to the tool
260-
func checkConfig(url string, zoom, cc int) {
261+
func checkConfig(url string, zoom, minzoom, cc int) {
261262
// ensure a URL is provided
262263
if url == "" {
263264
fmt.Printf("No cache URL specified!\n" +
@@ -280,6 +281,12 @@ func checkConfig(url string, zoom, cc int) {
280281
os.Exit(1)
281282
}
282283

284+
// ensure valid minimum zoom level
285+
if minzoom < 0 {
286+
fmt.Printf("Provided minimum zoom level must be 0 or greater!\n")
287+
os.Exit(1)
288+
}
289+
283290
// ensure valid concurrency level
284291
if cc < 1 {
285292
fmt.Printf("Invalid concurrency level: %d. "+
@@ -288,7 +295,7 @@ func checkConfig(url string, zoom, cc int) {
288295
}
289296

290297
fmt.Printf("Config OK. URL: %s, Max zoom: %d, "+
291-
"Concurrency: %d\n\n", url, zoom, cc)
298+
"Min zoom: %d, Concurrency: %d\n\n", url, zoom, minzoom, cc)
292299
}
293300

294301
// printHelp will print the help message and exit with a status code of 0
@@ -299,19 +306,21 @@ func printHelp() {
299306

300307
const helpMessage = `
301308
Flags:
302-
--url Templated cache URL to prime. Ex: tile.company.com/{x}/{y}/{z}.png
303-
--zoom Max zoom depth to prime to. Usually in the range of 0-18 but can go deeper.
304-
--cc Maximum request concurrency. Defaults to 4 simultaneous requests.
305-
Take care not to exceed the rate limits of your tile provider!
306-
--header Add headers to all requests. Usage '--header name:value'
307-
--help Shows this help menu.
309+
--url Templated cache URL to prime. Ex: tile.company.com/{x}/{y}/{z}.png
310+
--zoom Max zoom depth to prime to. Usually in the range of 0-18 but can go deeper.
311+
--minzoom Minimum zoom level to start priming at. Defaults to 0.
312+
--cc Maximum request concurrency. Defaults to 4 simultaneous requests.
313+
Take care not to exceed the rate limits of your tile provider!
314+
--header Add headers to all requests. Usage '--header name:value'
315+
--help Shows this help menu.
308316
309317
Usage:
310318
xyz --url tile.company.com/{x}/{y}/{z}.png --zoom 8
311319
`
312320

313321
const usageUrl = "Templated cache URL to prime. Ex: tile.company.com/{x}/{y}/{z}.png"
314322
const usageZoom = "Max zoom depth to prime to. Defaults to 4. Usually in the range of 0-18 but can go deeper."
323+
const usageMinZoom = "Minimum zoom level to start priming at. Defaults to 0."
315324
const usageCc = "Maximum request concurrency. Defaults to 4 simultaneous requests. Take care not to exceed rate limits."
316325
const usageHeader = "Add headers to all requests. Usage '--header name:value'"
317326
const usageHelp = "Shows this help menu."

0 commit comments

Comments
 (0)