Add pkg directory

This commit is contained in:
Arnaud (Arhuman) ASSAD 2023-08-30 15:58:44 +02:00
parent 0940df8384
commit 936d812e9c
2 changed files with 47 additions and 0 deletions

18
pkg/web2/routes.go Normal file
View File

@ -0,0 +1,18 @@
package web2
import (
"github.com/gofiber/fiber/v2"
)
func (s *Server) Routes() {
s.router.Get("/hello", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
//s.router.Get("/login", adaptor.HTTPHandlerFunc(auth.LoginHandler))
// http.HandlerFunc -> fiber.Handler
//app.Get("/greet", adaptor.HTTPHandlerFunc(greet)
// where : func greet(w http.ResponseWriter, r *http.Request) { }
//app.Get("/greet", adaptor.HTTPHandler(handler(greet))
// where : func handler(f http.HandlerFunc) http.Handler { }
}

29
pkg/web2/server.go Normal file
View File

@ -0,0 +1,29 @@
package web2
import (
"github.com/gofiber/fiber/v2"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
)
type Server struct {
db *gorm.DB
log *logrus.Logger
router *fiber.App
}
// NewServer is a constructor for Server struct
// It takes a database connection and a logger as parameters
// It returns a pointer to a Server struct
func NewServer(db *gorm.DB, log *logrus.Logger) *Server {
app := fiber.New()
return &Server{
db: db,
log: log,
router: app,
}
}
func (s *Server) Run() {
s.router.Listen(":3000")
}