-
Install Go: Ensure that Go is installed on your machine. You can download and install Go from the official website: https://golang.org/dl/
-
Set up your project: Create a new directory for your project and navigate to it in your terminal.
-
Initialize Go module: Run the following command to initialize a Go module in your project directory:
go mod init <module-name>
Replace with the name of your project.
-
Install dependencies: Install the required packages by running the following commands:
go get -u github.com/gin-gonic/gin go get -u github.com/jackc/pgx go get -u github.com/jackc/pgx/pgxpool go get -u github.com/golang-migrate/migrate/v4
-
Set up your database: Make sure you have a PostgreSQL database set up and running. Take note of the database connection details (host, port, username, password, database name).
-
Create a .env file: In your project's root directory, create a new file named .env and open it in a text editor.
Add database credentials to .env file: Inside the .env file, add the following lines and replace the placeholders with your actual database credentials:
dbUrl = "postgres://login:password@host:5432/dbname"
-
Use the Migrate package to manage your database migrations. You can use instructions from official github: https://github.com/golang-migrate/migrate
-
Clone or download your Golang project from your version control system (e.g., Git).
-
Build and run the project: In the terminal, navigate to the root directory of your project. Run the following command to build and run your project:
go run .
This command assumes that the main Go file is in the root directory and named main.go.
-
Endpoints:
To save CSV data in the database, make a POST request to the endpoint
http://localhost:<port>/promotions/csv
To retrieve records by ID, make a GET request to the endpoint
http://localhost:<port>/promotions/:id
You can use a tool like cURL or Postman to send requests
-
Notifications
You must be signed in to change notification settings - Fork 0
hellenaa/goproject
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Golang project to upload and save CSV and get items by ID
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published