chore: better path joining
This commit is contained in:
parent
ab47d5c35a
commit
4b2fd8dd04
1 changed files with 10 additions and 3 deletions
13
main.go
13
main.go
|
@ -5,7 +5,9 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -46,15 +48,20 @@ or: cmd | curl --data-binary @- %s
|
|||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
os.WriteFile("db/"+uuid.String(), body, 0644)
|
||||
fmt.Fprintf(w, hostURL+uuid.String())
|
||||
os.WriteFile(path.Join("db", uuid.String()), body, 0644)
|
||||
url, err := url.JoinPath(hostURL, uuid.String())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Fprintf(w, url)
|
||||
log.Printf("paste created: uuid=%s", uuid.String())
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
})
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir("db")))
|
||||
http.Handle("/", http.FileServer(http.Dir(databasePath)))
|
||||
|
||||
log.Printf("Starting server on %s", listenAddr)
|
||||
log.Fatal(http.ListenAndServe(listenAddr, nil))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue