Skip to content

Commit 6981e94

Browse files
authored
Merge pull request #3 from GabrielNatPr0/main
feat: organize code added comentaries
2 parents db07a46 + 9ae6618 commit 6981e94

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

cmd/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import (
66
"api-go/middleware"
77
"api-go/repository"
88
"api-go/usecase"
9-
109
"github.com/gin-gonic/gin"
1110
)
1211

1312
func main() {
14-
1513
server := gin.Default()
1614

1715
dbConnection, err := db.ConnectDb()
16+
1817
if err != nil {
1918
panic(err)
19+
return err
2020
}
2121

2222
ProductRepository := repository.NewProductRepository(dbConnection)
@@ -25,12 +25,17 @@ func main() {
2525

2626
ProductController := controller.NewProductController(*ProductUseCase)
2727

28-
server.GET("/ping", func(ctx *gin.Context) {
28+
server.GET("/ping-dev", func(ctx *gin.Context) {
2929
ctx.JSON(200, gin.H{
30-
"message": "primeiros testes",
30+
"message": "Servidor Está ativo!",
3131
})
3232
})
3333

34+
/*
35+
routes server
36+
products
37+
*/
38+
3439
protected := server.Group("/")
3540
protected.Use(middleware.AuthMiddleware())
3641
{

db/conn.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ import (
77
_ "github.com/lib/pq"
88
)
99

10+
/*
11+
configuration
12+
db
13+
*/
14+
15+
/*
16+
var (
17+
host = "go_db" string
18+
port = 5432 int
19+
user = "postgres" string
20+
password = "1234" int
21+
dbname = "postgres"
22+
23+
)*/
24+
1025
const (
1126
host = "go_db"
1227
port = 5432
@@ -29,7 +44,7 @@ func ConnectDb() (*sql.DB, error) {
2944
panic(err)
3045
}
3146

32-
fmt.Println("connected to" + dbname)
47+
//fmt.Println("connected to" + dbname)
3348

3449
return db, nil
3550
}

model/product.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package model
22

3+
/*
4+
Product Struct
5+
*/
6+
37
type Product struct {
48
ID int `json:"id"`
59
Name string `json:"name"`
610
Price float64 `json:"price"`
7-
}
11+
}

repository/product_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (pr *ProductRepository) DeleteProduct(id int) error {
122122

123123
_, err = query.Exec(id)
124124
if err != nil {
125-
fmt.Println(err)
125+
//fmt.Println(err)
126126
return err
127127
}
128128

0 commit comments

Comments
 (0)