Skip to content

Commit

Permalink
Updated to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
onattech committed Jan 12, 2023
1 parent 0e479d4 commit e22e277
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/onattech/toolkit
module github.com/onattech/toolkit/v2

go 1.19
6 changes: 2 additions & 4 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -189,11 +188,10 @@ func (t *Tools) Slugify(s string) (string, error) {
// DownloadStaticFile downloads a file, and tries to force the browser to avoid displaying it
// in the browser window by setting content disposition. It also allows specification of the
// display name
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, p, file, displayName string) {
fp := path.Join(p, file)
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, displayName string) {
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", displayName))

http.ServeFile(w, r, fp)
http.ServeFile(w, r, pathName)
}

// JSONResponse is the type used for sending JSON around
Expand Down
2 changes: 1 addition & 1 deletion tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestTools_DownloadStaticFile(t *testing.T) {

var testTool Tools

testTool.DownloadStaticFile(rr, req, "./testdata", "pic.jpg", "moon.jpg")
testTool.DownloadStaticFile(rr, req, "./testdata/pic.jpg", "moon.jpg")

res := rr.Result()
defer res.Body.Close()
Expand Down

0 comments on commit e22e277

Please sign in to comment.