summary refs log tree commit diff
path: root/cmd/portgate.go
blob: 2bc06933a626cf95eaefb1777fcdd50c2ade1266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.")
	}

	// Load and Parse all Portgate templates
	templates, _ := portgate.LoadAllTemplates()

	// Create handler for requests
	handler := handlers.NewRequestHandler(&config, templates)

	// 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)
	}
}