Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

pejovski/search

Repository files navigation

Search

Micro-service with functionality for adding, deleting and searching for products in a product catalog elastic DB.

Supports full-text search, with filters, sorting and pagination.

It has simple api-key authentication and versioning.

Open API 3.0 UI

DB and App dockerized

Simple CI for GitHub and GitLab

Requirements

go version 1.13
docker
docker-compose
golang-statik: sudo apt install golang-statik
mockgen: sudo apt install mockgen

Installation

Use go mod to install dependencies.

go mod tidy

Run docker-compose to build docker images and run containers.

docker-compose up -d

if the command above returns this error

es01 exited with code 78

that is because

elasticsearch     | [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

Therefore we need to increase the vm.max_map_count limit:

sudo sysctl -w vm.max_map_count=524288

Now we need to edit /etc/sysctl.conf so the setting will also be in effect after a reboot.

Look for any vm.max_map_count line in /etc/sysctl.conf. If you find one, set its value to 524288. If there is no such line present, add the line

vm.max_map_count=524288

to the end of /etc/sysctl.conf

Usage

docker-compose up -d

wait some time until elasticsearch is ready

  • open Search API
  • use Api-Key: e9435160-1df0-4d27-b0bf-9b3edd9d5737 for authentication

Testing

Example tests added in controller/controller_test.go

For production systems make sure the coverage is 100%

go test ./... -race -cover

Create Mock

 mockgen -source=[interface_name].go -destination=[interface_name]_mock.go -package=[package_name]

Swagger update

Architecture and Design

The project code follows the design principles from the resources bellow

Microsoft Micro-Services

https://docs.microsoft.com/en-us/dotnet/architecture/microservices/index

Uber Go Code Structure

https://www.youtube.com/watch?v=nLskCRJOdxM

  • extended with receivers and emitters for working with events

Rest HTTP Server by Go veteran

https://www.youtube.com/watch?v=rWBSMsLG8po

License

MIT

About

Search microservice with Rest API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published