Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afaguilarr/go-example-webserver
Example Web API built using Go, NGINX, Python (for testing), and probably React in the future
https://github.com/afaguilarr/go-example-webserver
circleci dependabot docker docker-compose gherkin go grpc http nginx postgresql pytest pytest-bdd shell-scripts
Last synced: 2 months ago
JSON representation
Example Web API built using Go, NGINX, Python (for testing), and probably React in the future
- Host: GitHub
- URL: https://github.com/afaguilarr/go-example-webserver
- Owner: afaguilarr
- License: mit
- Created: 2021-10-24T17:13:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-06T07:02:37.000Z (over 1 year ago)
- Last Synced: 2024-09-29T10:27:38.630Z (3 months ago)
- Topics: circleci, dependabot, docker, docker-compose, gherkin, go, grpc, http, nginx, postgresql, pytest, pytest-bdd, shell-scripts
- Language: Go
- Homepage:
- Size: 34 MB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# README.md
## Description
This project aims to create an example go/golang web-server.
The `go-example-webserver/docs` directory includes the explanation of the application being built (the docs will have a broader scope than the actual code at the point you're reading this probably).
Any feedback is welcome since this is a public project.## Building and running the project
The project is integrated with docker, then running the following commands after setting up a `.env` file at `go-example-webserver/.env`, should be enough (there is an example env file in the root directory):
```bash
docker-compose build
docker-compose --env-file ./.env up
docker-compose --env-file ./.env up -d # if you want to run the containers in the background
```## Functional tests and Manual tests
To run the functional tests written in python, or any manual tests, we have to set up the DB, in order to do that, execute the following goose command:
```bash
docker-compose run webserver sh bin/goose_apply_migrations.sh ${POSTGRES_USERNAME} ${POSTGRES_PASSWORD}
```
And then just run:
```bash
docker-compose run python_tests pytest
```## Go Unit tests
To run the unit tests:
```bash
docker-compose run go_builder sh bin/go_test.sh
```
This will generate a coverage report at `./app/src/report/coverage.html`.## Go linting
We have some different commands to run Go linters, run the following commands:
```bash
docker-compose run go_builder sh bin/go_fmt.sh
docker-compose run go_builder sh bin/go_vet.sh
docker-compose run go_builder sh bin/staticcheck.sh
```## Python linting
To run pylint use the following command:
```bash
docker-compose run python_tests sh bin/pylint.sh
```## Goose and PostgreSQL DB Info
To connect to the DataBase, use the following command (replace ${MICROSERVICE} by the affected microservice):
```bash
docker-compose run postgres_${MICROSERVICE} psql --host=postgres_${MICROSERVICE} --username=${POSTGRES_USERNAME} --dbname=${POSTGRES_DB_NAME}
```To create a new DB migration use the following command:
```bash
docker-compose run ${MICROSERVICE} sh bin/goose_new_migration.sh ${MIGRATION_NAME}
```To apply the db_migrations use the following command:
```bash
docker-compose run ${MICROSERVICE} sh bin/goose_apply_migrations.sh ${POSTGRES_CONTAINER} ${POSTGRES_USERNAME} ${POSTGRES_PASSWORD} ${POSTGRES_DB_NAME}
```To unapply the db_migrations use the following command:
```bash
docker-compose run ${MICROSERVICE} sh bin/goose_downgrade_migration.sh ${POSTGRES_CONTAINER} ${POSTGRES_USERNAME} ${POSTGRES_PASSWORD} ${POSTGRES_DB_NAME}
```## Adding or updating Go dependencies
To add new go dependencies we just have to use the following commands inside the `app` directory. This can be done through your local environment as long as you have go installed.
```bash
go get ${DEPENDENCY}@${VERSION}
go mod tidy
```If you are adding an executable go dependency, add it to the `tools.go` file and follow the instructions there (basically the same instructions above).
## Adding or updating Python dependencies
So far I've been adding these manually to the `test/requirements.txt` file. After that, we need to re-build the python container.
## Updating Protos
Update the `app/bin/generate_protos.sh` and `test/bin/generate_protos.sh` and then execute the following commands:
```bash
docker-compose run go_builder sh bin/generate_protos.sh
docker-compose build python_tests
docker-compose run python_tests sh bin/generate_protos.sh
```## Updating Webserver endpoints
In order to modify the webserver endpoints, we have to follow some guidelines related to the go-swagger spec generation:
* To generate the go swagger files:
```bash
docker-compose run go_builder swagger generate spec -o ./swagger/swagger.yaml
docker-compose run go_builder swagger generate spec -o ./swagger/swagger.json
```## Check the Swagger docs (HTML)
Going to the `localhost/swagger` URL in a browser (after running the project) should be enough!
## Call gRPC endpoints manually
Execute the following command:
```bash
docker-compose run go_builder grpcurl -plaintext -d '${REQUEST_BODY}' ${MICROSERVICE}:8080 go_webserver.${MICROSERVICE}.${SERVICE}/${RPC}
```## Call Webserver endpoints manually
Will refine this section soon but the webserver endpoints should be accessible via postman, curl or any other http client by calling the `localhost/api` URL.
## Changes and Pull Requests
Every change has to be made via a Pull Request, and CircleCI checks are needed.
Even for the repo administrators.## Github Releases
To understand how Github releases work for this repository, this documentation should be useful: https://github.com/go-modules-by-example/index/blob/master/009_submodules/README.md.
This section will probably change once a Vue js UI is added.## Dependabot
This repo uses Dependabot to keep its Go dependencies up to date.
The config was created following this blog article: https://github.blog/2020-06-01-keep-all-your-packages-up-to-date-with-dependabot/
And the github docs: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates