router_anonym.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // package router_anonym -- реализация HTTP-роутера с анонимным хранилищем
  2. package router_anonym
  3. import (
  4. "fmt"
  5. "time"
  6. "git.p78su.freemyip.com/svi/gostore/internal/serv_http/router_anonym/anonym_del"
  7. "git.p78su.freemyip.com/svi/gostore/internal/serv_http/router_anonym/anonym_find"
  8. "git.p78su.freemyip.com/svi/gostore/internal/serv_http/router_anonym/anonym_list"
  9. "git.p78su.freemyip.com/svi/gostore/internal/serv_http/router_anonym/anonym_put"
  10. "git.p78su.freemyip.com/svi/gostore/internal/serv_http/router_anonym/anonym_read"
  11. "git.p78su.freemyip.com/svi/gostore/pkg/types"
  12. "github.com/gofiber/fiber/v2"
  13. )
  14. // RouterAnonym -- реализация HTTP-роутера с анонимным хранилищем
  15. type RouterAnonym struct {
  16. *anonym_put.AnonymPut
  17. *anonym_read.AnonymRead
  18. *anonym_find.AnonymFind
  19. *anonym_del.AnonymDel
  20. *anonym_list.AnonymList
  21. serv types.IService
  22. servHttp types.IServHttp
  23. router fiber.Router
  24. }
  25. // NewRouterAnonym -- возвращает новый HTTP-роутер с анонимным хранилищем
  26. func NewRouterAnonym(servHttp types.IServHttp) (*RouterAnonym, error) {
  27. if servHttp == nil {
  28. return nil, fmt.Errorf("NewRouterAnonym(): IServHttp==nil")
  29. }
  30. serv := servHttp.Service()
  31. sf := &RouterAnonym{
  32. serv: serv,
  33. servHttp: servHttp,
  34. router: servHttp.FiberApp().Group("/anonym"),
  35. }
  36. sf.router.Get("/", sf.get)
  37. var err error
  38. sf.AnonymPut, err = anonym_put.NewAnonymPut(servHttp, sf.router)
  39. if err != nil {
  40. return nil, fmt.Errorf("NewRouterAnonym(): in create AnonymPut, err=\n\t%w", err)
  41. }
  42. sf.AnonymRead, err = anonym_read.NewAnonymRead(servHttp, sf.router)
  43. if err != nil {
  44. return nil, fmt.Errorf("NewRouterAnonym(): in create AnonymRead, err=\n\t%w", err)
  45. }
  46. sf.AnonymFind, err = anonym_find.NewAnonymFind(servHttp, sf.router)
  47. if err != nil {
  48. return nil, fmt.Errorf("NewRouterAnonym(): in create AnonymFind, err=\n\t%w", err)
  49. }
  50. sf.AnonymDel, err = anonym_del.NewAnonymDel(servHttp, sf.router)
  51. if err != nil {
  52. return nil, fmt.Errorf("NewRouterAnonym(): in create AnonymDel, err=\n\t%w", err)
  53. }
  54. sf.AnonymList, err = anonym_list.NewAnonymList(servHttp, sf.router)
  55. if err != nil {
  56. return nil, fmt.Errorf("NewRouterAnonym(): in create AnonymList, err=\n\t%w", err)
  57. }
  58. sf.router.Post("/time", sf.time)
  59. return sf, nil
  60. }
  61. // Возвращает страницу анонимного раздела
  62. func (sf *RouterAnonym) get(c *fiber.Ctx) error {
  63. return c.Render("anonym_put", fiber.Map{})
  64. }
  65. // Возвращает текущее время
  66. func (sf *RouterAnonym) time(c *fiber.Ctx) error {
  67. strTime := time.Now().Local().Format("2006-01-02 15:04:05 MST -07")
  68. return c.SendString(strTime)
  69. }