Skip to content

Commit

Permalink
adding user-custom path string capture using request context
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Sep 20, 2023
1 parent e772fba commit c7c6674
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions japicore/routeHandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func DownloadHandler(fileIo *file_io_handler.FileIoHandler) bunrouter.HandlerFun

func UploadHandler(fileIo *file_io_handler.FileIoHandler, queue *FileIoQueue) bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {

uniquePath := readUniquePath(req)
_ = uniquePath

var byteBuffer bytes.Buffer
var wg sync.WaitGroup
wg.Add(1)
Expand Down
12 changes: 12 additions & 0 deletions japicore/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package japicore

import (
"github.com/uptrace/bunrouter"
"net/http"
"sync"

Expand Down Expand Up @@ -37,3 +38,14 @@ func processUpload(w http.ResponseWriter, fileIo *file_io_handler.FileIoHandler,

return m.Fid()
}

func readUniquePath(req bunrouter.Request) string {
uniquePath, ok := req.Context().Value("uniquePath").(string)
if !ok {
return ""
}
if len(uniquePath) == 0 {
return ""
}
return uniquePath
}

0 comments on commit c7c6674

Please sign in to comment.