1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package httpserver
- import (
- "net/http"
- "github.com/gin-gonic/gin"
- )
- type Controller struct {
- Config *HttpServerConfig
- }
- /*
- Returns a new Controller struct to register routes to the gin router
- :param cfg: A pointer to an HttpServerConfig struct
- */
- func NewController(cfg *HttpServerConfig) *Controller {
- return &Controller{Config: cfg}
- }
- /*
- This handler will be responsible for proxying out the GET requests that the server recieves
- */
- func (c *Controller) Get(ctx *gin.Context) {
- }
- /*
- This handler will be responsible for proxying any POST requests
- */
- func (c *Controller) Post(ctx *gin.Context) {
- req, err := http.NewRequest()
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Error creating the request.",
- "Msg:": err.Error(),
- })
- return
- }
- req.Header.Add("user-agent", c.Config.UserAgent)
- req.Header.Add("Referer", c.Config.AllowedDomain)
- req.Host = c.Config.RevProxySite
- req.Proto = ctx.Request.Method
- req.RequestURI = ctx.FullPath()
- }
|