aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/download.go
blob: a640ea2e261042ffcccd532bc94b1b85178bbd4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"net/http"

	"github.com/gorilla/mux"
)

func gameDownloader(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	game := vars["game"]

	libMu.RLock()
	g, ok := Lib.Games[game]
	libMu.RUnlock()
	if !ok {
		Logger.Printf("Missing: %s", game)
		http.Error(w, "Game is missing", 404)
		return
	}

	w.Header().Add("Content-type", "application/tar")

	err := g.Package(w)
	if err != nil {
		Logger.Printf("Error Sending game: %s", err)
		// Headers already sent, don't bother sending an error
	}

}