git clone https://github.com/ronaudinho/wp
cd wp/cmd/wp-sqlite
go run main.go
- scripts under
script
directory are to be run from root directory e.gbash script/test.sh
instead ofcd script; bash test.sh
- docker build using script requires binary to built first, hence
bash script/build.sh
bash script/dockerize.sh
- running on docker not tried locally, some issue with my docker container network to host connection LOL but i would assume it works on machine where docker is properly set up
- probably emulating chat application
- chat would use websocket for sending as well most likely, so slight modification to the usual flow
an attempt to follow
├── cmd # entrypoint to application, allow for different implementations
│ └── wp-sqlite # in this case, using SQLite for persistence
│ │ ├── main.go
│ └── ...
├── internal
│ ├── service # service layer is for business logic
│ │ ├── message.go
│ │ └── message_test.go
│ ├── model # model layer is for shared model
│ │ └── message.go
│ ├── repository # repository layer is for data persistence
│ │ └── sqlite # in this case, using SQLite
│ │ ├── message.go
│ │ └── message_test.go
│ └── handler # handler layer is for interfaces with external application
│ ├── rest # in this case, using REST
│ │ ├── message.go
│ │ └── message_test.go
│ └── websocket # in this case, using websocket
│ ├── message.go
│ └── message_test.go
├── pkg # globally shared package
│ └── validator # validator to validate request body
│ ├── validate.go
│ ├── validate_test.go
│ └── ...
└── ...
- based on quick searching, mqtt is a layer above websocket, go mqtt library depends on go websockets library, hence using websocket in this exercise
- websocket looks simpler and easier to implement for now
- while usage of database is not required, getting all previously sent messages calls for some persistence layer. could have use cache but using embedded database instead
- declaring interface in the place where it is consumed, as per this talk
- black box testing preferance
- should have done white box testing for one unexported function in pkg/validator but nvm