flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 32fd85e62324db1a34b5e78e1ef7b61cee31edde
parent 73cee727f63bc89ce49772003f5a61a79f98af8d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 18 Nov 2020 19:21:32 -0800

Don't create file until save

Diffstat:
Mhttp.go | 13+++++++++----
Mmain.go | 1-
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/http.go b/http.go @@ -98,10 +98,15 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { return } // create directories if dne - os.MkdirAll(path.Dir(filePath), os.ModePerm) - f, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, 0644) - defer f.Close() - fileBytes, err := ioutil.ReadAll(f) + f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) + var fileBytes []byte + if os.IsNotExist(err) { + fileBytes = []byte{} + err = nil + } else { + defer f.Close() + fileBytes, err = ioutil.ReadAll(f) + } if err != nil { log.Println(err) renderError(w, InternalServerErrorMsg, 500) diff --git a/main.go b/main.go @@ -91,7 +91,6 @@ func getLocalPath(filesPath string) string { func getCreator(filePath string) string { l := len(strings.Split(c.FilesDirectory, "/")) r := strings.Split(filePath, "/")[l] - fmt.Println(filePath, c.FilesDirectory, r) return r }