Parcourir la source

working on routing and stuff

AETH-erial il y a 1 an
Parent
commit
0a273cc479
4 fichiers modifiés avec 89 ajouts et 4 suppressions
  1. 45 0
      pkg/controller.go
  2. 40 0
      pkg/include.go
  3. 1 0
      pkg/routing.go
  4. 3 4
      pkg/server.go

+ 45 - 0
pkg/controller.go

@@ -0,0 +1,45 @@
+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.Header.Add()
+
+}

+ 40 - 0
pkg/include.go

@@ -0,0 +1,40 @@
+package httpserver
+
+import (
+	"encoding/json"
+	"os"
+)
+
+type HttpServerConfig struct {
+	HttpPort      int    `json:"http_port"`
+	HttpsPort     int    `json:"https_port"`
+	AllowedDomain string `json:"allowed_domain"`
+	UserAgent     string `json:"user_agent"`
+	UseSsl        bool   `json:"use_ssl"`
+}
+
+type Cookie struct {
+	Name     string `json:"name"`
+	Value    string `json:"value"`
+	MaxAge   int    `json:"max_age"`
+	Path     string `json:"path"`
+	Domain   string `json:"domain"`
+	Secure   bool   `json:"secure"`
+	HttpOnly bool   `json:"http_only"`
+}
+
+func ReadConfig(loc string) (*HttpServerConfig, error) {
+
+	f, err := os.ReadFile(loc)
+	if err != nil {
+		return nil, err
+	}
+	var cfg HttpServerConfig
+	err = json.Unmarshal(f, &cfg)
+	if err != nil {
+		return nil, err
+	}
+
+	return &cfg, err
+
+}

+ 1 - 0
pkg/routing.go

@@ -0,0 +1 @@
+package httpserver

+ 3 - 4
pkg/server.go

@@ -1,5 +1,4 @@
-package main
+package httpserver
 
-func main() {
-
-}
+const HTTPS_PORT = 443
+const HTTP_PORT = 80