|
1 | | -package main |
2 | | - |
3 | | -import ( |
4 | | - "database/sql" |
5 | | - "fmt" |
6 | | - "log" |
7 | | - "net/http" |
8 | | - |
9 | | - "github.com/gin-gonic/gin" |
10 | | - "github.com/wpcodevo/golang-postgresql-grpc/config" |
11 | | - "github.com/wpcodevo/golang-postgresql-grpc/controllers" |
12 | | - dbConn "github.com/wpcodevo/golang-postgresql-grpc/db/sqlc" |
13 | | - "github.com/wpcodevo/golang-postgresql-grpc/routes" |
14 | | - |
15 | | - _ "github.com/lib/pq" |
16 | | -) |
17 | | - |
18 | | -var ( |
19 | | - server *gin.Engine |
20 | | - db *dbConn.Queries |
21 | | - |
22 | | - AuthController controllers.AuthController |
23 | | - AuthRoutes routes.AuthRoutes |
24 | | -) |
25 | | - |
26 | | -func init() { |
27 | | - config, err := config.LoadConfig(".") |
28 | | - |
29 | | - if err != nil { |
30 | | - log.Fatalf("could not load config: %v", err) |
31 | | - } |
32 | | - |
33 | | - conn, err := sql.Open(config.PostgreDriver, config.PostgresSource) |
34 | | - if err != nil { |
35 | | - log.Fatalf("could not connect to postgres database: %v", err) |
36 | | - } |
37 | | - |
38 | | - db = dbConn.New(conn) |
39 | | - |
40 | | - fmt.Println("PostgreSQL connected successfully...") |
41 | | - |
42 | | - AuthController = *controllers.NewAuthController(db) |
43 | | - AuthRoutes = routes.NewAuthRoutes(AuthController) |
44 | | - |
45 | | - server = gin.Default() |
46 | | -} |
47 | | - |
48 | | -func main() { |
49 | | - config, err := config.LoadConfig(".") |
50 | | - |
51 | | - if err != nil { |
52 | | - log.Fatalf("could not load config: %v", err) |
53 | | - } |
54 | | - |
55 | | - router := server.Group("/api") |
56 | | - |
57 | | - router.GET("/healthchecker", func(ctx *gin.Context) { |
58 | | - ctx.JSON(http.StatusOK, gin.H{"status": "success", "message": "Welcome to Golang with PostgreSQL"}) |
59 | | - }) |
60 | | - |
61 | | - AuthRoutes.AuthRoute(router) |
62 | | - log.Fatal(server.Run(":" + config.Port)) |
63 | | -} |
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "database/sql" |
| 5 | + "fmt" |
| 6 | + "log" |
| 7 | + "net/http" |
| 8 | + |
| 9 | + "github.com/gin-gonic/gin" |
| 10 | + "github.com/wpcodevo/golang-postgresql-grpc/config" |
| 11 | + "github.com/wpcodevo/golang-postgresql-grpc/controllers" |
| 12 | + dbConn "github.com/wpcodevo/golang-postgresql-grpc/db/sqlc" |
| 13 | + "github.com/wpcodevo/golang-postgresql-grpc/routes" |
| 14 | + |
| 15 | + _ "github.com/lib/pq" |
| 16 | +) |
| 17 | + |
| 18 | +var ( |
| 19 | + server *gin.Engine |
| 20 | + db *dbConn.Queries |
| 21 | + |
| 22 | + AuthController controllers.AuthController |
| 23 | + AuthRoutes routes.AuthRoutes |
| 24 | +) |
| 25 | + |
| 26 | +func init() { |
| 27 | + config, err := config.LoadConfig(".") |
| 28 | + |
| 29 | + if err != nil { |
| 30 | + log.Fatalf("could not load config: %v", err) |
| 31 | + } |
| 32 | + |
| 33 | + conn, err := sql.Open(config.PostgreDriver, config.PostgresSource) |
| 34 | + if err != nil { |
| 35 | + log.Fatalf("could not connect to postgres database: %v", err) |
| 36 | + } |
| 37 | + |
| 38 | + db = dbConn.New(conn) |
| 39 | + |
| 40 | + fmt.Println("PostgreSQL connected successfully...") |
| 41 | + |
| 42 | + AuthController = *controllers.NewAuthController(db) |
| 43 | + AuthRoutes = routes.NewAuthRoutes(AuthController) |
| 44 | + |
| 45 | + server = gin.Default() |
| 46 | +} |
| 47 | + |
| 48 | +func main() { |
| 49 | + config, err := config.LoadConfig(".") |
| 50 | + |
| 51 | + if err != nil { |
| 52 | + log.Fatalf("could not load config: %v", err) |
| 53 | + } |
| 54 | + |
| 55 | + router := server.Group("/api") |
| 56 | + |
| 57 | + router.GET("/healthchecker", func(ctx *gin.Context) { |
| 58 | + ctx.JSON(http.StatusOK, gin.H{"status": "success", "message": "Welcome to Golang with PostgreSQL"}) |
| 59 | + }) |
| 60 | + |
| 61 | + AuthRoutes.AuthRoute(router) |
| 62 | + log.Fatal(server.Run(":" + config.Port)) |
| 63 | +} |
0 commit comments