This is a sample project that demonstrates how to build a RESTful API with Go, Neo4j, and the Hexagonal architecture. The project uses Gin Gonic as the web framework and includes integration tests.
To get started with the project, follow these steps:
- Clone the repository:
git clone https://github.com/sembh1998/go-hexagonal-neo4j-api.git
- Install the dependencies:
go mod tidy
- Set up your environment variables: create a
.env
file at the root of the project and add the following variables:
- NEO4J_URI=bolt://localhost:7687
- NEO4J_USER=neo4j
- NEO4J_PASSWORD=password
- Run the tests:
go test -v ./...
- Start the server:
go run cmd/server/main.go
You should now be able to access the API at http://localhost:8080
.
The API exposes the following endpoints:
GET /products
: returns a list of all productsGET /products/:id
: returns the details of a specific productPOST /products
: creates a new productPUT /products/:id
: updates an existing productDELETE /products/:id
: deletes an existing product
The project follows the Hexagonal architecture, with the following structure:
├── adapters # adapters to external dependencies (e.g. Neo4j)
├── cmd # command-line interfaces (e.g. server)
├── internal # internal packages
│ ├── domain # domain logic (e.g. entities, repositories)
│ ├── handlers # HTTP handlers (e.g. controllers)
│ └── usecases # use cases (e.g. business logic)
├── tests # integration tests
└── .env # environment variables (not included in the repo)
- Go 1.20
- Neo4j 5.6.0
- Gin Gonic 1.9.0
- Testify 1.8.1 (for testing)
- Faker 1.2.3 (for testing)
Contributions to the project are welcome. To contribute:
- Fork the project
- Create a feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push the branch:
git push origin my-new-feature
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE
file for details.