controller.go 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package httpserver
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type Controller struct {
  7. Config *HttpServerConfig
  8. }
  9. /*
  10. Returns a new Controller struct to register routes to the gin router
  11. :param cfg: A pointer to an HttpServerConfig struct
  12. */
  13. func NewController(cfg *HttpServerConfig) *Controller {
  14. return &Controller{Config: cfg}
  15. }
  16. /*
  17. This handler will be responsible for proxying out the GET requests that the server recieves
  18. */
  19. func (c *Controller) Get(ctx *gin.Context) {
  20. }
  21. /*
  22. This handler will be responsible for proxying any POST requests
  23. */
  24. func (c *Controller) Post(ctx *gin.Context) {
  25. req, err := http.NewRequest()
  26. if err != nil {
  27. ctx.JSON(500, map[string]string{
  28. "Error": "Error creating the request.",
  29. "Msg:": err.Error(),
  30. })
  31. return
  32. }
  33. req.Header.Add("user-agent", c.Config.UserAgent)
  34. req.Header.Add("Referer", c.Config.AllowedDomain)
  35. req.Header.Add()
  36. }