Skip to content

Commit

Permalink
readme mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
ojones committed Oct 14, 2018
1 parent 7fb2a72 commit d023b94
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# compiled binary
simple-storage-server

# Binaries for programs and plugins
*.exe
*.dll
Expand Down
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
# simple-storage-server
Simple storage server homework assignment for interview. Go microservice for managing multipler user accounts for personal file storage.
>Go microservice that allows registered users to store files.
Completed all instructions. Tried to include best practices but could use improvements. Should give a general idea of my capabilities.
# File Storage Microservice

Suggestions welcome.
* [Good practices](#good-practices)
* [Usage](#usage)
* [Run](#run)
* [Test](#test)
* [Before Production](#before-production)
* [Personal Note](#personal-note)

# Good practices
- Use store interface which allows for easy mock testing
- Seperate struct for configs used to instantiate service
- Vendored dependencies
- JWT session validation
- Authorization data set in request context

### Build and run
From within repo:
# Usage
- Register
- Login
- List files
- Put file
- Get file
- Delete file

# Run
From root folder:
```
go build && ./simple-storage-server
```
Localhost address is http://localhost:9999/

Expected file form field is "file"

### Test
# Test
```
go test
```

### TODO if this were a production project
Handle space limitations<br>
More test coverage - gave just a few examples<br>
Store registered users to disk - currently an in memory map, <br>
Create and cleanup folders on startup - folders included in project<br>
Logger middleware instead - currenlty just does validation<br>
Integration tests<br>
Read configs from text file<br>
Docker image<br>
# Before Production
- Handle space limitations
- More test coverage
- Store registered users to disk
- Create and cleanup folders on startup
- Logger middleware
- Integration tests
- Read configs from text file
- Docker image
- Publish API

# Personal Note
What's the big deal with microservices? Honestly, it's just the next logical step in the evolution of service oriented architecture (SOA).

SOA allowed us to escape the single point of failure of having everything run on one server. Back then, network bottlenecks prevented us from over using services but that is much less of problem now.

With clouds, we can freely decouple data and the logic that goes with them across infrastructure. Just imagine your working code stays up. When something goes wrong, only one service goes down. It's a beauatiful dream. The cost is the heavy lifting of configuring, monitoring, and complicating your system.
6 changes: 3 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Service) filesListHandler(w http.ResponseWriter, r *http.Request) {
w.Write(output)

// Log
fmt.Println("file listed")
fmt.Println("files listed")
}

func (s *Service) filesPutHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *Service) filesPutHandler(w http.ResponseWriter, r *http.Request) {
defer file.Close()

// Put file in store
if err := s.Store.putFile(filename, folderpath, file); err != nil {
if err := s.Store.addFile(filename, folderpath, file); err != nil {
fmt.Println(errors.New("cannot write file"))
http.Error(w, "", 500)
return
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *Service) filesDeleteHandler(w http.ResponseWriter, r *http.Request) {
}

// Delete file from store
err := s.Store.deleteFile(filepath)
err := s.Store.removeFile(filepath)
if err != nil {
fmt.Println(err.Error())
http.Error(w, "", 500)
Expand Down
8 changes: 4 additions & 4 deletions mock_Storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type MockStorer struct {
mock.Mock
}

// deleteFile provides a mock function with given fields: filepath
func (_m *MockStorer) deleteFile(filepath string) error {
// removeFile provides a mock function with given fields: filepath
func (_m *MockStorer) removeFile(filepath string) error {
ret := _m.Called(filepath)

var r0 error
Expand Down Expand Up @@ -78,8 +78,8 @@ func (_m *MockStorer) listFiles(folderpath string) ([]byte, error) {
return r0, r1
}

// putFile provides a mock function with given fields: filename, folderpath, file
func (_m *MockStorer) putFile(filename string, folderpath string, file io.Reader) error {
// addFile provides a mock function with given fields: filename, folderpath, file
func (_m *MockStorer) addFile(filename string, folderpath string, file io.Reader) error {
ret := _m.Called(filename, folderpath, file)

var r0 error
Expand Down
Binary file modified simple-storage-server
Binary file not shown.
8 changes: 4 additions & 4 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
// Storer decouple and to test without writing to disk
type Storer interface {
listFiles(folderpath string) ([]byte, error)
putFile(filename string, folderpath string, file io.Reader) error
addFile(filename string, folderpath string, file io.Reader) error
getFile(filepath string) ([]byte, int64, error)
deleteFile(filepath string) error
removeFile(filepath string) error
}

type store struct{}
Expand Down Expand Up @@ -41,7 +41,7 @@ func (s *store) listFiles(folderPath string) ([]byte, error) {
return output, nil
}

func (s *store) putFile(filename string, folderpath string, file io.Reader) error {
func (s *store) addFile(filename string, folderpath string, file io.Reader) error {
// Read file
fileBytes, err := ioutil.ReadAll(file)
if err != nil {
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s *store) getFile(filepath string) ([]byte, int64, error) {
return buffer, filesize, nil
}

func (s *store) deleteFile(filepath string) error {
func (s *store) removeFile(filepath string) error {
// Delete file
err := os.Remove(filepath)
if err != nil {
Expand Down

0 comments on commit d023b94

Please sign in to comment.