Skip to content

Commit

Permalink
Add controller code
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 28, 2023
1 parent be39ce7 commit 2ddc8e9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/deploy/controller.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 2ddc8e9

Please sign in to comment.