Test Task
Ensure you have Go installed. You can download and install it from Go's official site. Verify the installation by running:
go version
Install golangci-lint for linting your Go code. You can install it using the following command:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint --version
Install swagger for generating models from the API specification. You can install the swagger command-line tool using the following command:
go install github.com/go-swagger/go-swagger/cmd/swagger@latest
swagger version
Ensure you have make installed on your system. Most Unix-like systems come with make pre-installed. On Debian-based systems, you can install it using:
sudo apt-get install build-essential
On MacOS, you can install it using:
xcode-select --install
Ensure you have a .env.local file with the necessary environment variables. This file is sourced when running the application.
Runs embedded unit and integration tests
make test
Can run specific test by its name
make test-n name=TestIntegration_CreatePostHandler
Runs golangci-lint to lint the Go code.
make lint
Runs lint and tests.
make check
Builds the application and runs it, sourcing environment variables from .env.local.
make run
Builds the application with optimization flags.
make build
Generates models using Swagger from the provided API specification.
make models
curl -X POST http://localhost:8080/posts \
-H "Content-Type: application/json" \
-d '{
"title": "Title 1",
"content": "Quaerat sit dolorem velit. Ipsum non tempora magnam neque tempora. Tempora dolorem adipisci tempora neque labore. Dolorem sed dolore sed. Voluptatem consectetur dolor voluptatem. Quiquia adipisci voluptatem modi dolore. Dolor etincidunt neque consectetur dolor. Numquam etincidunt voluptatem sit amet tempora. Modi dolorem sed magnam consectetur. Dolor dolorem est amet magnam velit.",
"author": "Author 1"
}'
curl -X GET http://localhost:8080/posts
curl -X GET http://localhost:8080/posts/1
curl -X PUT http://localhost:8080/posts/1 \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title 1",
"content": "Updated content for the first post.",
"author": "Updated Author 1"
}'
curl -X DELETE http://localhost:8080/posts/1
To run the server, use the following command:
go run main.go
Or you can build and run as executable file
make build
make run