-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (41 loc) · 823 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"load-balancer/service"
"log"
"net/http"
"net/http/httputil"
"net/url"
"sync"
)
func main() {
domains := []string{}
var pool service.ServicePool
for _, domain := range domains {
url, err := url.Parse(domain)
if err != nil {
message := fmt.Sprintf("Unable to parse domain: %s", domain)
panic(message)
}
pool.Services = append(pool.Services,
&service.Service{
URL: url,
Alive: true,
ReverseProxy: httputil.NewSingleHostReverseProxy(url)})
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
http.HandleFunc("/", pool.Balance)
fmt.Println("we up")
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}()
go func() {
log.Println("Starting routine health checks")
pool.GroupHealthCheck()
}()
wg.Wait()
}