Code candidates will extend as part of their technical interview process. The order-up service handles all order-specific calls including creating orders, checking the status on orders, etc. This service is part of a larger microservice backend for a online marketplace.
You also will need to install Go. Then clone this
this repository and run go mod tidy
within this repository to download all
necessary dependencies locally.
The top-level only contains a single main.go
file which holds the main
function. If you ran go build ./.
that would produce a order-up
binary that
would start by executing the main
function in main.go
.
The api
package handles incoming HTTP requests with a REST paradigm and calls
various functions based on the path. This package uses the storage
package to
perform the necessary functionality for each API call. The tests use a mocked
storage instance.
The storage
package contains the database calls necessary for persisting and
retrieving orders. The methods are missing the bodies of the functions since
you're expected to fill them in with whatever database and implementation you
think satisfies the tests and documented functionality.
The mocks
package just contains a helper function for mocking an external
service by accepting an http.Handler and returning a *http.Client as well as
generated code for mocking a *storage.Instance
. This simply makes the tests
easier in the api
package.
go mod tidy
downloads all dependencies and updatego.mod
file with any new dependenciesgo test -v -race ./...
tests all files and subdirectories. You can instead dogo test -v ./storage/...
to only test the storage package. Any public function with the formatTestX(*testing.T)
will automatically be called bygo test
. Typically these functions are placed inX_test.go
files. You can pass a regex to-run
like-run ^TestInsertOrder$
in order to just run tests matching the regex.go fmt ./...
reformats the go files according to the gofmt specgo vet ./...
prints out most-likely errors or mistakes in Go codego get $package
adds a new dependency to the current project
The easiest way to run databases locally for testing is using Docker. You can use any database you're familiar with these are just some examples.
Alternatively you can sign up for an online free tier of a hosted version of these databases (like MongoDB Atlas, or CockroachDB Cloud) if that's easier.
docker run --rm -it -p 27017:27017 mongo
docker run --rm -it -p 5432:5432 -e POSTGRES_PASSWORD=password postgres
docker run --rm -it -p 6379:6379 redis
You can use any database or driver you're familiar with these are just some examples.
- mongo and the companion bson. See this tutorial.
- database/sql but this must be combined with a driver package like pq. See this tutorial
- radix Redis driver
Remember when you're adding new packages to run go mod tidy
to ensure the
go.mod and go.sum files are updated.