Miki Tebeka committed e40ee82


Comments (0)

Files changed (1)

+// Current backend
 var backend string
 func main() {
+// forward proxies traffic between local socket and remote backend
 func forward(local net.Conn, remoteAddr string) {
 	remote, err := net.Dial("tcp", remoteAddr)
 	if remote == nil {
 	go io.Copy(remote, local)
+// die prints error message and aborts the program
 func die(msg string) {
 	fmt.Fprintf(os.Stderr, "error: %s\n", msg)
+// startHttpServer start the HTTP server interface in a given port
 func startHttpServer(port int) {
 	http.HandleFunc("/switch", switchHandler)
 	http.HandleFunc("/current", currentHandler)
 	http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
+// switchHandler handler /switch and switches backend
 func switchHandler(w http.ResponseWriter, req *http.Request) {
 	newBackend := req.FormValue("backend")
 	if len(newBackend) == 0 {
 	currentHandler(w, req)
+// currentHandler handles /current and return the current backend
 func currentHandler(w http.ResponseWriter, req *http.Request) {
 	w.Header().Set("Content-Type", "text/plain")
 	fmt.Fprintf(w, "%s\n", backend)