- Handlers for managing sources (Admin API)
- Handler for retrieving news by given parameters:
- Verifying user input, displaying appropriate messages/errors
- Dynamic fetching news from external APIs:
- Making requests to external APIs (ABC,BBC, etc.), and store it. Not from static files as were before
- Covered code with unit and integration tests
- Made server secure with HTTPS
- Added logging
- Containerized application with docker
Here I would like to explain the purpose of each directory.
Main logic of the application is there. Cmd has few sub folders:
- Parsers - Parsing various data types
- Filters - Filtering news by various parameters
- Types - Types folder is used to avoid cycling imports. Object that are used in multiple packages (e.g. Parsing Parameters) lives there
- Server - server initialization and configuration
- Server/handlers - handlers attached to the server
- Validator - Validating layer using chain of responsibility pattern
Documentation, specfile and C4 model, and usage/response examples with images
Go-Gator server contains few handlers. Few of them are used by admins to manage list of available
sources.
News handler is used by clients to fetch news.
P.S. This example assumes that server is running on port :443, however you can change it any time.
- GET:
/news
- Returns list of news, filtering them by parameters.
- Available parameters:
ts-from=2024-05-12
News will be retrieved starting from that timestamp
ts-to=2024-05-18
No news will be retrieved, where publication date is bigger than provided parameter
sources=bbc,washingtontimes
News will be retrieved ONLY from mentioned sources (separated by ',')
keywords=Ukraine,Chine
News will be filtered by existence of keywords in title or description
- GET:
/admin/sources
- Returns list of available sources
- POST
/admin/sources
- Add new sources to the list
If were provided already existing source - will return an error.
- PUT '/admin/sources' - Update already existing sources
In source, you can update either format, and/or endpoint. If were provided not-existing source - will return an error
- DELETE '/admin/sources' - Update already existing sources
If were provided not-existing source - will return an error
- Using Golang:
go build -o ./bin/go-gator
- Build golang binary
./bin/go-gator
You can change default parameters, such as updates frequency, server port and certificates:
-
-f - Changes news updates frequency
-
-p - Specify port on which server will be operating
-
-c and -k - Are used for SSL certificate and key
-
Using Docker
docker build -t go-gator .
docker run go-gator -p 443:443
You can change your port to anything that you like, but destination port on the container should be 443.
- With Taskfile
Docker:
task docker-build DOCKER_IMAGE_NAME={your_image_name}
task docker-run DOCKER_IMAGE_NAME={your_image_name}
Golang:
task build
task run