Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health check #178

Merged
merged 14 commits into from
Dec 16, 2024
2 changes: 2 additions & 0 deletions backend/.sqlc/queries/version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: GetDBVersion :one
SELECT version();
3 changes: 3 additions & 0 deletions backend/common/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package common

var VERSION string
235 changes: 235 additions & 0 deletions backend/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions backend/db/version.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 41 additions & 7 deletions backend/internal/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package server

import (
"KonferCA/SPUR/db"
"KonferCA/SPUR/storage"
"fmt"
"os"

"github.com/jackc/pgx/v5/pgxpool"
"github.com/labstack/echo/v4"
)

type Server struct {
DBPool *pgxpool.Pool
Echo *echo.Echo
}

/*
Initializes a new Server instance and creates a connection pool to the database.
The database connection string can be controlled by setting the following env variables:
Expand All @@ -35,11 +31,17 @@ func New() (*Server, error) {
return nil, err
}

store, err := storage.NewStorage()
if err != nil {
return nil, err
}

e := echo.New()

s := Server{
DBPool: pool,
Echo: e,
DBPool: pool,
Echo: e,
Storage: store,
}

s.setupMiddlewares()
Expand All @@ -48,6 +50,38 @@ func New() (*Server, error) {
return &s, nil
}

/*
Implement the CoreServer interface GetDB method that simply
returns the current db pool.
*/
func (s *Server) GetDB() *pgxpool.Pool {
return s.DBPool
}

/*
Implement the CoreServer interface GetQueries method that simply
returns a new instance of the db.Queries struct.
*/
func (s *Server) GetQueries() *db.Queries {
return db.New(s.DBPool)
}

/*
Implement the CoreServer interface GetStorage method that simply
returns an storage instance.
*/
func (s *Server) GetStorage() *storage.Storage {
return s.Storage
}

/*
Implement the CoreServer interface GetEcho method that simply
returns the root echo instance.
*/
func (s *Server) GetEcho() *echo.Echo {
return s.Echo
}

/*
Start the server and binds it to the given port.
*/
Expand Down
4 changes: 3 additions & 1 deletion backend/internal/server/routes.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package server

import v1 "KonferCA/SPUR/internal/v1"

/*
Setup all the API routes of any version that will be available in this server.
*/
func (s *Server) setupRoutes() {

v1.SetupRoutes(s)
}
13 changes: 13 additions & 0 deletions backend/internal/server/types.go
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
package server

import (
"KonferCA/SPUR/storage"

"github.com/jackc/pgx/v5/pgxpool"
"github.com/labstack/echo/v4"
)

type Server struct {
juancwu marked this conversation as resolved.
Show resolved Hide resolved
DBPool *pgxpool.Pool
Echo *echo.Echo
Storage *storage.Storage
}
Loading
Loading