all repos — homestead @ 20dd619b8605660dac67fa435d711e5f22da3174

Code for my website

ensure reasonable ordering of declarations in source

Alan Pearce
commit

20dd619b8605660dac67fa435d711e5f22da3174

parent

6f41d182abaf1af16fd0cc697abf0f2e9ce54c5c

1 file changed, 24 insertions(+), 25 deletions(-)

changed files
M shared/storage/files/reader.goshared/storage/files/reader.go
@@ -32,6 +32,30 @@
return r, nil } +func (r *Reader) GetFile(urlPath string) (*storage.File, error) { + return r.files[urlPath], nil +} + +func (r *Reader) CanonicalisePath(path string) (cPath string, differs bool) { + cPath = path + switch { + case strings.HasSuffix(path, "/index.html"): + cPath, differs = strings.CutSuffix(path, "index.html") + + case strings.HasSuffix(path, ".html"): + cPath, differs = strings.CutSuffix(path, ".html") + + case !strings.HasSuffix(path, "/") && r.files[path+"/"] != nil: + cPath, differs = path+"/", true + + case strings.HasSuffix(path, "/"): + if cPath, differs := strings.CutSuffix(path, "/"); differs && r.files[cPath] != nil { + return cPath, differs + } + } + + return cPath, differs +} func (r *Reader) registerFile(urlpath string, filepath string) error { file, err := r.OpenFile(urlpath, filepath) if err != nil {
@@ -76,28 +100,3 @@ }
return nil } - -func (r *Reader) GetFile(urlPath string) (*storage.File, error) { - return r.files[urlPath], nil -} - -func (r *Reader) CanonicalisePath(path string) (cPath string, differs bool) { - cPath = path - switch { - case strings.HasSuffix(path, "/index.html"): - cPath, differs = strings.CutSuffix(path, "index.html") - - case strings.HasSuffix(path, ".html"): - cPath, differs = strings.CutSuffix(path, ".html") - - case !strings.HasSuffix(path, "/") && r.files[path+"/"] != nil: - cPath, differs = path+"/", true - - case strings.HasSuffix(path, "/"): - if cPath, differs := strings.CutSuffix(path, "/"); differs && r.files[cPath] != nil { - return cPath, differs - } - } - - return cPath, differs -}