Add pkg directory
This commit is contained in:
parent
0940df8384
commit
936d812e9c
|
@ -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 { }
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue