This is a back-end only implementation of a simple calendar application to schedule slots between candidates and interviewers. Done as a challenge for a technical interview, it uses entirely Go with the Gin framework and standard RESTful practices.
├── api
│ ├── controllers.go # "Middleware"-like handlers
│ ├── database.go # All BD operations
│ ├── models.go # Models of our entities
│ └── routers.go # Routing, sets the endpoints
├── go.mod # Module file
├── gorm.db # sqlite DB used by gorm
├── go.sum # Module file
├── main.go # Just a small stub to launch the server
This was developed has a Go Module, so it can be easily imported into other projects.
The project was developed and tested with go1.16.2 linux/amd64, but a Dockerfile is provided so it can be deployed quickly without needing to install Go and setup a Workspace.
- Install the latest Go for your desired platform.
- Setup your workspace ($GOPATH) accordingly, so you can import everything needed to run the project:
export GOPATH="/your/target/workspace/dir"
- Confirm Go is working with go version, and run the project from this directory (no need to build it):
go run main.go
If you have Docker installed, you can use the provided Dockerfile to build and run a containerized version of this project, without needing to install Go or anything else.
- In the project directory, build the image:
sudo docker build -t go-calendar-api .
- Run it (note that the port is hardcoded in main.go - change it there too if you don't want to use port 8080):
sudo docker run -p 8080:8080 -it go-calendar-api
The API endpoints can be viewed in routers.go. It follows a RESTful fashion, so the 3 main components (users, slots and scheduling) can be reached on api/user, api/slots/ and api/scheduler.
The operation itself might require a parameter being passed in the URI, a JSON payload in the request body, or both.
Once it's running, it can be interacted directly with any network transfer tool like Wget or curl:
curl --request POST \
--data '{"name":"Carl", "week":33, "day": "monday", "hour_start":9, "hour_end":10}' \
http://localhost:8080/api/slots/
curl --request GET http://localhost:8080/api/slots/Carl
Alternatively, any modern browser with Console/Developer tools can render JSON replies without any problem. For even fancier control, Postman is a really powerful option.
A simple bash script, test_example.sh is provided, simulating a real life scenario. Just chmod +x it and pass as first argument the API's port number.