summary refs log tree commit diff
path: root/cmd
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-07-26 14:12:26 +0200
committerMelonai <einebeere@gmail.com>2021-07-26 14:12:26 +0200
commit7819a23171145e8a626e8357e88446817c8785dc (patch)
treef8834b1952583844f62c520ab0d8285b8ec2416f /cmd
parent3fe27839f0418d13a42524fd10102d0ef62c05f5 (diff)
downloadportgate-7819a23171145e8a626e8357e88446817c8785dc.tar.zst
portgate-7819a23171145e8a626e8357e88446817c8785dc.zip
Refactor into packages
Diffstat (limited to 'cmd')
-rw-r--r--cmd/portgate.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/portgate.go b/cmd/portgate.go
new file mode 100644
index 0000000..afa756a
--- /dev/null
+++ b/cmd/portgate.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+	"github.com/valyala/fasthttp"
+	"log"
+
+	"portgate"
+	"portgate/handlers"
+)
+
+func main() {
+	log.Print("Starting Portgate...")
+
+	// Get global Portgate config.
+	config, err := portgate.GetConfig()
+	if err != nil {
+		log.Fatal("Failed to get Portgate config.")
+	}
+
+	// Create handler for requests
+	handler := handlers.NewRequestHandler(&config)
+
+	// Start to listen to the outside world.
+	log.Print("Listening for requests on port 8080.")
+	err = fasthttp.ListenAndServe(config.PortgateAddress(), handler.HandleRequest)
+	if err != nil {
+		log.Fatalf("Portgate server could not be started: %s", err)
+	}
+}