DimNS

Untitled

Dec 30th, 2020
949
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "database/sql"
  5.     "myapp/internal/config"
  6.     "myapp/internal/database"
  7.  
  8.     _ "github.com/go-sql-driver/mysql"
  9.     "github.com/gofiber/fiber/v2"
  10. )
  11.  
  12. type BaseHandler struct {
  13.     db  *sql.DB
  14.     app *fiber.App
  15. }
  16.  
  17. type HomeHandler struct {
  18.     BaseHandler
  19. }
  20.  
  21. func (h *HomeHandler) home(c *fiber.Ctx) error {
  22.     return c.SendString("Hello, home!")
  23. }
  24.  
  25. func NewHomeHandler(bh *BaseHandler) {
  26.     h := HomeHandler{*bh}
  27.  
  28.     h.app.Get("/home", h.home)
  29. }
  30.  
  31. type UserHandler struct {
  32.     BaseHandler
  33. }
  34.  
  35. func (h *UserHandler) user(c *fiber.Ctx) error {
  36.     return c.SendString("Hello, user!")
  37. }
  38.  
  39. func NewUserHandler(bh *BaseHandler) {
  40.     h := UserHandler{*bh}
  41.  
  42.     h.app.Get("/user", h.user)
  43. }
  44.  
  45. func main() {
  46.     cfg := config.CreateConfig()
  47.     db := database.Connect(cfg)
  48.  
  49.     app := fiber.New()
  50.  
  51.     bh := &BaseHandler{
  52.         db:  db,
  53.         app: app,
  54.     }
  55.  
  56.     NewHomeHandler(bh)
  57.     NewUserHandler(bh)
  58.  
  59.     app.Listen(cfg.WebServer.Address)
  60. }
  61.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×