postgres

command
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Setting Up a Postgres Database

This guide will walk you through the process of setting up a Postgres database using Docker and running a Go application that interacts with it.

Step 1: Run a Postgres Database

To use the Postgres Docker instance, run the following command in your terminal:

docker run -d --name postgres \
  -p 5432:5432 \
  -e POSTGRES_USER=root \
  -e POSTGRES_PASSWORD=root \
  -e POSTGRES_DB=employees \
  -v "$(pwd)/data:/var/lib/postgresql/data" \
  postgres:13.2-alpine

Note : Replace root with your desired password.

Set Password in Environment Variable

Set the password in an environment variable for easier configuration:

export DB_PASSWORD=root

Step 2: Configure and Run the Go Application

  • Define your Postgres database configuration in your Go application.

  • Ensure you have Xray installed and imported in your Go application.

  • Checkout Integration.md for a detailed doc and main.go for code sample, demonstrating how to connect to Postgres using Xray.

  • Once you have the code, run the following commands:

    go mod tidy
    go run main.go
    

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL