diff --git a/cmd/server/main.go b/cmd/server/main.go index 073609b..cc484c2 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -7,10 +7,10 @@ import ( "net/http" "github.com/gin-gonic/gin" - "github.com/wpcodevo/golang-postgresql-grpc/config" - "github.com/wpcodevo/golang-postgresql-grpc/controllers" - dbConn "github.com/wpcodevo/golang-postgresql-grpc/db/sqlc" - "github.com/wpcodevo/golang-postgresql-grpc/routes" + "github.com/wpcodevo/golang-postgresql-api/config" + "github.com/wpcodevo/golang-postgresql-api/controllers" + dbConn "github.com/wpcodevo/golang-postgresql-api/db/sqlc" + "github.com/wpcodevo/golang-postgresql-api/routes" _ "github.com/lib/pq" ) @@ -59,5 +59,10 @@ func main() { }) AuthRoutes.AuthRoute(router) + + server.NoRoute(func(ctx *gin.Context) { + ctx.JSON(http.StatusNotFound, gin.H{"status": "fail", "message": fmt.Sprintf("Route %s not found", ctx.Request.URL)}) + }) + log.Fatal(server.Run(":" + config.Port)) } diff --git a/controllers/signup.controller.go b/controllers/signup.controller.go index 29d77db..9341cf7 100644 --- a/controllers/signup.controller.go +++ b/controllers/signup.controller.go @@ -5,8 +5,8 @@ import ( "time" "github.com/gin-gonic/gin" - db "github.com/wpcodevo/golang-postgresql-grpc/db/sqlc" - "github.com/wpcodevo/golang-postgresql-grpc/utils" + db "github.com/wpcodevo/golang-postgresql-api/db/sqlc" + "github.com/wpcodevo/golang-postgresql-api/utils" ) type AuthController struct { diff --git a/go.mod b/go.mod index 1b08770..6bf0d49 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wpcodevo/golang-postgresql-grpc +module github.com/wpcodevo/golang-postgresql-api go 1.18 diff --git a/readMe.md b/readMe.md index 8b89b15..1ee7e3b 100644 --- a/readMe.md +++ b/readMe.md @@ -1,4 +1,31 @@ -# API with Golang, PostgreSQL, SQLC, Docker & Gin Gonic +# How to Setup SQLC CRUD API with Golang and Gin Gonic -### 1. API with Golang, PostgreSQL, SQLC & Gin Gonic: Project Setup -[API with Golang, PostgreSQL, SQLC & Gin Gonic: Project Setup](https://codevoweb.com/api-golang-postgresql-sqlc-gin-gonic-project-setup) \ No newline at end of file +This article will teach you how to set up a SQLC API project with Golang, standard Database/SQL package, Gin Gonic, PostgreSQL, Golang-migrate, and Docker-compose. You will also learn how to generate Golang database CRUD functions and Structs with the SQLC compiler. The SQLC Golang API will use a PostgreSQL database and run on the Gin Gonic HTTP server. We will use the Golang-migrate package to push the SQL schema to the database. + +![How to Setup SQLC CRUD API with Golang and Gin Gonic](https://codevoweb.com/wp-content/uploads/2022/06/How-to-Setup-SQLC-CRUD-API-with-Golang-and-Gin-Gonic.webp) + +## Topics Covered + +- How to Setup Golang with PostgreSQL +- How to Run Database Migration in Golang +- Generate Golang CRUD Functions and Structs with SQLC +- Initialize the Golang Project +- Connect the Golang App to PostgreSQL +- How to Hash Passwords in Golang +- Create a Route Handler to Register User +- Setup Routing +- Configure the Main Server File +- Testing the Golang Gin API + +Read the entire article here: [https://codevoweb.com/api-golang-postgresql-sqlc-gin-gonic-project-setup](https://codevoweb.com/api-golang-postgresql-sqlc-gin-gonic-project-setup) + +Articles in this series: + +### 1. How to Setup SQLC CRUD API with Golang and Gin Gonic +[How to Setup SQLC CRUD API with Golang and Gin Gonic](https://codevoweb.com/api-golang-postgresql-sqlc-gin-gonic-project-setup) + +### 2. Build Golang & PostgreSQL API: JWT Access and Refresh Tokens +[Build Golang & PostgreSQL API: JWT Access and Refresh Tokens](https://codevoweb.com/golang-postgresql-api-access-and-refresh-tokens) + +### 3. Golang CRUD RESTful API with SQLC and PostgreSQL +[Golang CRUD RESTful API with SQLC and PostgreSQL](https://codevoweb.com/golang-crud-restful-api-with-sqlc-and-postgresql) diff --git a/routes/auth.route.go b/routes/auth.route.go index a33e178..7643bbf 100644 --- a/routes/auth.route.go +++ b/routes/auth.route.go @@ -2,7 +2,7 @@ package routes import ( "github.com/gin-gonic/gin" - "github.com/wpcodevo/golang-postgresql-grpc/controllers" + "github.com/wpcodevo/golang-postgresql-api/controllers" ) type AuthRoutes struct {