https://github.com/ntrv3390/go-crud
Basic crud operations in golang with postgresql and programmatic database migrations.
https://github.com/ntrv3390/go-crud
crud go golang postgresql rest-api
Last synced: about 2 months ago
JSON representation
Basic crud operations in golang with postgresql and programmatic database migrations.
- Host: GitHub
- URL: https://github.com/ntrv3390/go-crud
- Owner: Ntrv3390
- Created: 2025-01-24T12:15:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-28T05:30:19.000Z (over 1 year ago)
- Last Synced: 2025-02-01T22:31:41.323Z (over 1 year ago)
- Topics: crud, go, golang, postgresql, rest-api
- Language: Go
- Homepage:
- Size: 7.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# CRUD with go and postgres
## Prerequisites
The project uses go language hence you need to install it. You can install golang from this url -> [Install GoLang](https://go.dev/doc/install).
In this project I have used postgreSQL for database. Based on your requirements you can use any of the database you're comfortable with and can remove the postgreSQL dependencies and add your database dependencies to it. If you want to continue using postgreSQL just install it from this url -> [Install PostgrSQL](https://www.postgresql.org/download) and then read the below section.
### Setting up .env file
Now that you have installed all the required files and modules, you have to make a .env file and then copy the contents of .env.example file to .env file and change the enviroment variables value accordingly.
### Running the code
Firstly you need to install all the project dependencies. If you do not have a go.mod file run the following command to create one `go mod init `. Once it is created then run this `go mod tidy` to install all the required dependencies.
At this point you have all the dependencies installed to run the project. Now this project also includes programmatic database migrations. So the project has 3 CMD commands to either run the migrations or the server. The commands are as follows:
1) `go run src/main.go migrateUp` - This will run all the up migrations.
2) `go run src/main.go migrateDown` - This will run all the down migrations.
3) `go run src/main.go run` - This will start the server.
The starting point of the project is in src folder named main.go.
## Enjoy playing with API's - make updates and hit a PULL Request to merge 🎉