From 2ddc8e94347e6af7f29965c91e3c79996d61bcaa Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:00:07 +0000 Subject: [PATCH] Add controller code --- internal/deploy/controller.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 internal/deploy/controller.go diff --git a/internal/deploy/controller.go b/internal/deploy/controller.go new file mode 100644 index 0000000..da76622 --- /dev/null +++ b/internal/deploy/controller.go @@ -0,0 +1,34 @@ +package deploy + +import ( + "fmt" + "net" + "net/http" +) + +type ReverseProxyController struct { + srv *http.Server +} + +func NewReverseProxyController() *ReverseProxyController { + return &ReverseProxyController{} +} + +func (c *ReverseProxyController) ServeHTTP(w http.ResponseWriter, req *http.Request) { + +} + +func (c *ReverseProxyController) Listen() (port int, err error) { + listener, err := net.Listen("tcp", ":0") + if err != nil { + return 0, fmt.Errorf("net.Listen failed: %s", err) + } + port = listener.Addr().(*net.TCPAddr).Port + c.srv = &http.Server{Addr: ":0", Handler: c} + go c.srv.Serve(listener) + return port, nil +} + +func (c *ReverseProxyController) Terminate() { + c.srv.Close() +}