Initial import
This commit is contained in:
commit
a06573253d
|
@ -0,0 +1,11 @@
|
||||||
|
# web
|
||||||
|
|
||||||
|
`import "git.doolta.com/doolta/kit/web"`
|
||||||
|
|
||||||
|
* [Overview](#pkg-overview)
|
||||||
|
* [Examples](#pkg-examples)
|
||||||
|
* [Index](#pkg-index)
|
||||||
|
|
||||||
|
## <a name="pkg-overview">Overview</a>
|
||||||
|
## <a name="pkg-examples">Examples</a>
|
||||||
|
## <a name="pkg-index">Index</a>
|
|
@ -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 { }
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue