A Basic Load Balancer written in Go. The main aim of this project is to learn how load balancer(at least, the basic ones) function. The secondary aim was to deepen my understanding of Go.
- Create a basic server (or multiple) like this (Keep them in separate directories):
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Response from Server 1")
})
http.ListenAndServe(":8081", nil)
}- Run the server(s)
- Run the Load Balancer
go run main.go -port=3030 -backends=http://localhost:8081- Check the functioning in the terminal where the load balancer is running & using
curl http://localhost:3030in a separate terminal.