commit a06573253dda534bbfad297e416fafadbcb929f8 Author: Arnaud (Arhuman) ASSAD Date: Tue Jul 4 17:53:14 2023 +0200 Initial import diff --git a/README.md b/README.md new file mode 100644 index 0000000..d6d7a0a --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# web + +`import "git.doolta.com/doolta/kit/web"` + +* [Overview](#pkg-overview) +* [Examples](#pkg-examples) +* [Index](#pkg-index) + +## Overview +## Examples +## Index diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b0d7678 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.doolta.com/doolta/kit + +go 1.20 diff --git a/web/routes.go b/web/routes.go new file mode 100644 index 0000000..fc5dd56 --- /dev/null +++ b/web/routes.go @@ -0,0 +1,26 @@ +package web + +import ( + "doolta.com/api/auth" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/adaptor" +) + +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)) + /* + r.HandleFunc("/logout", auth.LogoutHandler).Methods("GET") + r.HandleFunc("/login_check", auth.LoginCheckHandler).Methods("POST") + r.HandleFunc("/signup", auth.SignupHandler).Methods("GET") + r.HandleFunc("/signup_check", auth.SignupCheckHandler).Methods("POST") + r.HandleFunc("/validate/{hash:.+}", auth.ValidateLinkHandler).Methods("GET") + */ + // 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 { } +} diff --git a/web/server.go b/web/server.go new file mode 100644 index 0000000..8b7a0f6 --- /dev/null +++ b/web/server.go @@ -0,0 +1,29 @@ +https://git.doolta.com/doolta/kithttps://git.doolta.com/doolta/kitpackage web + +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") +}