Last active
December 14, 2021 07:25
-
-
Save pavithran215/c1f9ad3a8699f0c143e2e164b2773e9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
) | |
var ( | |
arrayOfServers = []string{ | |
"http://127.0.0.1.8000", | |
"http://127.0.0.1.8001", | |
"http://127.0.0.1.8002", | |
"http://127.0.0.1.8003", | |
"http://127.0.0.1.8004", | |
} | |
index = 0 | |
) | |
func main() { | |
http.HandleFunc("/", forwardingServer) | |
log.Fatal(":5000", nil) | |
} | |
func forwardingServer(res http.ResponseWriter, req *http.Request) { | |
url := server() | |
rproxy := httputil.NewSingleHostReverseProxy(url) | |
rproxy.ServeHTTP(res, req) | |
} | |
func server() *url.URL { | |
nextIndex := (index + 1) % 5 | |
url, _ := url.Parse(arrayOfServers[index]) | |
index = nextIndex | |
return url | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
var ( | |
takingArgs = os.Args[1:] | |
) | |
func main() { | |
http.HandleFunc("/", simpleServer) | |
log.Fatal(http.ListenAndServe(takingArgs[0], nil)) | |
} | |
func simpleServer(res http.ResponseWriter, req *http.Request) { | |
fmt.Fprintf(res, "this is server %s", takingArgs[0]) | |
//fmt.Fprintf(res, "hi") | |
} | |
// a='/home/spurge/goNetworks/simpleServerArgs' | |
// cd $a; | |
// for i in {1..5} | |
// do | |
// go run main.go ":800$i" | |
// done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment