Access the service folder and execute the commands
- Build the image
docker build -t andreluzz/go-gfg-search-service .
- Run the image
docker run -it --network="host" andreluzz/go-gfg-search-service
Using --network="host" assuming elasticsearch server is running on the host at port 9200
Access the service folder and execute the commands
- Run the image overriding main command
docker run -it andreluzz/go-gfg-search-service go test ./... -cover
To execute the hole soluction with UI, Elasticsearch Server and Rest API service use docker-compose
docker-compose up
Access http://localhost to use the UI
Available query string parameters:
- q: query products.
- filter: filter products. Should be used passing the field_name:value.
- sort: define products order. Should be used passing filed_name:order_type. Available order types are: desc and asc.
- page: defines the page to select the results. Should be an integer.
- limit: defines the amount of items per page. Should be an integer.
Example:
http://localhost:8080/products?q=shoes&filter=brand:adidas&sort=title:desc&page=1&limit=20
Every request should have the headers to define API Version and Authentication.
For defining the API version use the header: "X-Service-Version" in the request. For test purpose there are two versions available: "v1" and "v2".
"X-Service-Version": "v2"
Authentication use the header: "Authorization" passing a valid token. For test use the token:
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.wDWyyGem9YgXDDbH3Un7YYcTB8IcN_BE4BMmS1tvlnE"
In this implementation was used the JSON Web Token (JWT) to generate the token. If is necessary create other tokens use https://jwt.io/ with the key "top-secret-signin-value-key".