Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
refactor, handle empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
titpetric committed Aug 21, 2017
1 parent d28a5eb commit 0b6e09b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions main_api.go
Expand Up @@ -110,10 +110,21 @@ func (api *API) ListHandler(w http.ResponseWriter, r *http.Request) {
}

func (api *API) Read(filePath string) (ReadResponse, error) {
response := ReadResponse{}
response := ReadResponse{
Location: Location{
Type: "file",
Path: filePath,
Name: path.Base(filePath),
Dir: path.Dir(filePath),
LastModified: time.Now().Format(time.UnixDate),
},
}
fullPath := path.Join(api.Path, filePath)
info, err := os.Stat(fullPath)
if err != nil {
if os.IsNotExist(err) {
return response, nil
}
return response, err
}
if !info.Mode().IsRegular() {
Expand All @@ -123,10 +134,6 @@ func (api *API) Read(filePath string) (ReadResponse, error) {
if err != nil {
return response, err
}
response.Type = "file"
response.Path = filePath
response.Name = path.Base(filePath)
response.Dir = path.Dir(filePath)
response.LastModified = info.ModTime().Format(time.UnixDate)
response.Contents = string(file)
return response, nil
Expand Down
2 changes: 1 addition & 1 deletion run-local.sh
@@ -1,3 +1,3 @@
#!/bin/bash
set -e
docker rm -f pendulum
./pendulum -port 8080

0 comments on commit 0b6e09b

Please sign in to comment.