This Go program implements a simple load balancer that distributes incoming HTTP requests among a set of backend servers.
- Go installed on your system.
- Clone this repository.
- Navigate to the directory containing the main.go file.
- Run the program using the
go run main.go
command. - Access the load balancer at
localhost:8000
in your web browser.
main.go
: Contains the main program logic.Server
: Interface defining methods for server properties and behavior.SimpleServer
: Struct representing a backend server with its address and a reverse proxy.LoadBalancer
: Struct managing a set of backend servers and distributing requests.newSimpleServer
: Creates a new instance ofSimpleServer
.newLoadBalancer
: Creates a new instance ofLoadBalancer
.getNextAvailableServer
: Selects the next available server using round-robin scheduling.serveProxy
: Forwards incoming requests to the selected server.main
: Initializes the load balancer with a set of backend servers and starts serving HTTP requests.
$ go run main.go
serving requests at 'localhost:8000'
Feel free to contribute by reporting issues, suggesting enhancements, or submitting pull requests.