Puppy Storer - A database for puppies
This project gives you experience in the following areas in Golang:
- struct
- types
- interfaces
- implementing interfaces with different implementations
- Concurrency and race-conditions
- Error handling
- Test coverage using test suite
Overall overview:
This simple program maintains a list of puppies.
A puppy has the following attributes:
It has a storer
interface which has the following CRUD methods for puppies:
- CreatePuppy
- ReadPuppy
- UpdatePuppy
- DeletePuppy
The storer interface has two different implementations:
MapStore
using native map structure
SyncStore
using sync.Map structure
How to build this project?
First thing first, you must install go and golangci-lint:
- Install go 1.12
- Install golangci-lint
To build the project, run the following command while you are in the root of the project folder:
go build ./...
How to run this project?
go run ./pkg/cmd/puppy-server/main.go --data fileName.json
Where fileName.json contains a list of puppies in json format, and for short version use -d
flag.
For any help with usage please use flag --help
How to test this project?
To test this project, follow the steps below:
- Run test cases:
go test ./...
- Lint it:
golangci-lint run
- Ensure 100% test coverage
go test -coverprofile=coverage.out ./... && go tool cover -html=coverage.out