Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/henvic/pgxtutorial
Example of how to build a web service using Go, PostgreSQL, and gRPC
https://github.com/henvic/pgxtutorial
go golang postgres postgresql
Last synced: 3 months ago
JSON representation
Example of how to build a web service using Go, PostgreSQL, and gRPC
- Host: GitHub
- URL: https://github.com/henvic/pgxtutorial
- Owner: henvic
- License: mit
- Created: 2021-11-14T23:13:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-17T23:56:26.000Z (6 months ago)
- Last Synced: 2024-06-19T00:24:25.252Z (6 months ago)
- Topics: go, golang, postgres, postgresql
- Language: Go
- Homepage:
- Size: 200 KB
- Stars: 117
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# pgxtutorial
[![GoDoc](https://godoc.org/github.com/henvic/pgxtutorial?status.svg)](https://godoc.org/github.com/henvic/pgxtutorial) [![Build Status](https://github.com/henvic/pgxtutorial/workflows/Integration/badge.svg)](https://github.com/henvic/pgxtutorial/actions?query=workflow%3AIntegration) [![Coverage Status](https://coveralls.io/repos/henvic/pgxtutorial/badge.svg)](https://coveralls.io/r/henvic/pgxtutorial)This is an accompanying repository of the article [Back to basics: Writing an application using Go and PostgreSQL](https://henvic.dev/posts/go-postgres) by [Henrique Vicente](https://henvic.dev/). Feel free to open issues to ask any questions or comment on anything.
## Environment variables
pgxtutorial uses the following environment variables:| Environment Variable | Description |
| - | - |
| PostgreSQL environment variables | Please check https://www.postgresql.org/docs/current/libpq-envars.html |
| INTEGRATION_TESTDB | When running go test, database tests will only run if `INTEGRATION_TESTDB=true` |
| OTEL_EXPORTER | When OTEL_EXPORTER=stdout or OTEL_EXPORTER=otel, telemetry is exported |## tl;dr
To play with it install [Go](https://go.dev/) on your system.
You'll need to connect to a [PostgreSQL](https://www.postgresql.org/) database.
You can check if a connection is working by calling `psql`.To run tests:
```sh
# Run all tests passing INTEGRATION_TESTDB explicitly
$ INTEGRATION_TESTDB=true go test -v ./...
```To run application:
```sh
# Create a database
$ psql -c "CREATE DATABASE pgxtutorial;"
# Set the environment variable PGDATABASE
$ export PGDATABASE=pgxtutorial
# Run migrations
$ tern migrate -m ./migrations
# Execute application
$ go run ./cmd/pgxtutorial
2021/11/22 07:21:21 HTTP server listening at localhost:8080
2021/11/22 07:21:21 gRPC server listening at 127.0.0.1:8082
```## See also
* [pgtools](https://github.com/henvic/pgtools/)
* [pgq](https://github.com/henvic/pgq)