From 3b536080e1a9944f87e3ae0f7c24b2457c30d1fa Mon Sep 17 00:00:00 2001 From: CODEVO Date: Sun, 2 Oct 2022 13:56:58 +0000 Subject: [PATCH 1/3] Update readMe.md --- readMe.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/readMe.md b/readMe.md index 6bfb0bd..6cb74a0 100644 --- a/readMe.md +++ b/readMe.md @@ -1,4 +1,37 @@ -# Build Golang RESTful API with Gorm, Gin and Postgres +# Build a RESTful CRUD API with Golang + +![Build a RESTful CRUD API with Golang](https://codevoweb.com/wp-content/uploads/2022/08/Build-a-RESTful-CRUD-API-with-Golang.webp) + +This article will teach you how to create a CRUD RESTful API in a Golang environment that runs on a Gin Gonic server and uses a PostgreSQL database. We’ll also discuss how you can build models, connect to the running SQL database server, and run database migrations with the GORM library. + +## Topics Covered + +- What is a REST API +- What is a REST API +- What is GORM +- What is Gin Gonic +- Create the Database Models with GORM +- Generating the SQL Table with GORM +- Creating CRUD Functions in a RESTful API + - Create a Constructor for the CRUD Operations + - Create Operation Route Handler + - Update Operation Route Handler + - Retrieve a Single Record Route Handler + - Retrieve All Records Route Handler + - Delete Operation Route Handler +- Creating Routes for the CRUD Operations +- Update/Configure the Golang API Server +- Testing the Golang CRUD API with Postman + - Log into the API + - Creating a New Record + - Updating the Record + - Request a Single Record + - Retrieve all Records with Paginated Results + - Delete a Record + +Read the entire article here: [https://codevoweb.com/build-restful-crud-api-with-golang](https://codevoweb.com/build-restful-crud-api-with-golang) + +Articles in this series: ### 1. How to Setup Golang GORM RESTful API Project with Postgres From fbdf5ef4deb2c1b128c8b4256eaef6b14a9b57a0 Mon Sep 17 00:00:00 2001 From: CODEVO Date: Sun, 2 Oct 2022 15:28:07 +0000 Subject: [PATCH 2/3] Update readMe.md --- readMe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readMe.md b/readMe.md index 6cb74a0..c704481 100644 --- a/readMe.md +++ b/readMe.md @@ -1,9 +1,9 @@ # Build a RESTful CRUD API with Golang -![Build a RESTful CRUD API with Golang](https://codevoweb.com/wp-content/uploads/2022/08/Build-a-RESTful-CRUD-API-with-Golang.webp) - This article will teach you how to create a CRUD RESTful API in a Golang environment that runs on a Gin Gonic server and uses a PostgreSQL database. We’ll also discuss how you can build models, connect to the running SQL database server, and run database migrations with the GORM library. +![Build a RESTful CRUD API with Golang](https://codevoweb.com/wp-content/uploads/2022/08/Build-a-RESTful-CRUD-API-with-Golang.webp) + ## Topics Covered - What is a REST API From c65231021647722146e88e427ea82e2a7afab1fe Mon Sep 17 00:00:00 2001 From: wpcodevo Date: Sat, 25 Mar 2023 20:55:25 +0000 Subject: [PATCH 3/3] updated --- .gitignore | 2 +- app.env | 19 +++++++++++++++++++ migrate/migrate.go | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app.env diff --git a/.gitignore b/.gitignore index 76b5cf8..d34b3e2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ TODO.md logs.txt .idea/ secret.md -app.env \ No newline at end of file +tmp/ \ No newline at end of file diff --git a/app.env b/app.env new file mode 100644 index 0000000..cb1c622 --- /dev/null +++ b/app.env @@ -0,0 +1,19 @@ +POSTGRES_HOST=127.0.0.1 +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password123 +POSTGRES_DB=golang-gorm +POSTGRES_PORT=6500 + +PORT=8000 +CLIENT_ORIGIN=http://localhost:3000 + +ACCESS_TOKEN_PRIVATE_KEY=LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCUEFJQkFBSkJBTzVIKytVM0xrWC91SlRvRHhWN01CUURXSTdGU0l0VXNjbGFFKzlaUUg5Q2VpOGIxcUVmCnJxR0hSVDVWUis4c3UxVWtCUVpZTER3MnN3RTVWbjg5c0ZVQ0F3RUFBUUpCQUw4ZjRBMUlDSWEvQ2ZmdWR3TGMKNzRCdCtwOXg0TEZaZXMwdHdtV3Vha3hub3NaV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ndNWXh6SXFERAplUUloQVA5UStrMTBQbGxNd2ZJbDZtdjdTMFRYOGJDUlRaZVI1ZFZZb3FTeW40YmpBaUVBaHVUa2JtZ1NobFlZCnRyclNWZjN0QWZJcWNVUjZ3aDdMOXR5MVlvalZVRlVDSUhzOENlVHkwOWxrbkVTV0dvV09ZUEZVemhyc3Q2Z08KU3dKa2F2VFdKdndEQWlBdWhnVU8yeEFBaXZNdEdwUHVtb3hDam8zNjBMNXg4d012bWdGcEFYNW9uUUlnQzEvSwpNWG1heWtsaFRDeWtXRnpHMHBMWVdkNGRGdTI5M1M2ZUxJUlNIS009Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t +REFRESH_TOKEN_PUBLIC_KEY=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZ3d0RRWUpLb1pJaHZjTkFRRUJCUUFEU3dBd1NBSkJBSWFJcXZXeldCSndnYjR1SEhFQ01RdHFZMTI5b2F5Rwo1WTBpRnBudWtCdVR6UWVZUFpBOGx4OC9lTUh3Rys1MlJGR3VxMmE2N084d2s3TDR5dnY5dVY4Q0F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ== +REFRESH_TOKEN_EXPIRED_IN=60m +REFRESH_TOKEN_MAXAGE=60 \ No newline at end of file diff --git a/migrate/migrate.go b/migrate/migrate.go index cf6fb7a..84832c6 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -18,6 +18,7 @@ func init() { } func main() { + initializers.DB.Exec("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"") initializers.DB.AutoMigrate(&models.User{}, &models.Post{}) fmt.Println("👍 Migration complete") }