This is a simple API structure for a Go application. The structure is designed to be modular and scalable. The structure is as follows:
- api contains the code for the backend of the application.
- storage contains the code for database management.
- types contains the code for structuring the data.
- utils contains the code for utility functions.
Entry point of the application is in the main.go
file. The main.go
file initializes the database and starts the server. The server is started on port 3000
by default. listenaddr
parameter in the main.go
file can be changed to start the server on a different port.
wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue. An optional LuaJIT script can perform HTTP request generation, response processing, and custom reporting.
brew install wrk
GET /questions
12 threads, 500 connections, 30 seconds
wrk -t12 -c500 -d30s --latency http://127.0.0.1:3000/questions
psql -h localhost -p 5432 -U admin -d main
INSERT INTO questions (isRequired, key, type, label) VALUES('0', 'test-key', 'text', '{ "tr": "Test Label for Turkish" }');
- Create Question struct in the types package.
- Add MustHaveKey method to Question struct
- Add GetQuestion, DeleteQuestion and UpdateQuestion methods
- Separate create and update validation functions
- Add minimum and maximum methods to QuestionLabel struct for validation
- Add minimum and maximum key length validation
- Add GET method for questions
- Add environment variables and read with https://github.com/joho/godotenv
- Add postgres and mongodb database
- Add seeding database
- Add mongodb storage
- Add database connection
- Add query methods
- Add Create method
- Add Get method
- Add Delete method
- Add List method
- Add pagination
- Add sorting
- add default sorting for createdAt field
- add custom sorting for different fields (updatedAt, createdAt)
- Add Update method
- Add postgres storage
https://vercel.com/docs/storage/vercel-postgres
- Migration https://sqlc.dev - sqlc generates fully type-safe idiomatic Go code from SQL https://github.com/pressly/goose https://www.freecodecamp.org/news/database-migration-golang-migrate/
- Add database connection and query methods
- Add database migration methods
- Create Form struct in the types package.
- add swagger documentation
- add swagger documentation for questions
- add CI/CD pipeline
- add github actions
- add dockerfile
- add gcp cloud run deployment
- Add validation for other question keys