diff options
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -2,15 +2,18 @@ package main import ( "crypto/tls" + "log" "net/http" "strings" "sync" + "time" ) const xForwardedProto = "X-Forwarded-Proto" const xForwardedProtoHTTPS = "https" type theApp struct { + appConfig domains domains lock sync.RWMutex } @@ -78,3 +81,46 @@ func (a *theApp) UpdateDomains(domains domains) { defer a.lock.Unlock() a.domains = domains } + +func (a *theApp) Run() { + var wg sync.WaitGroup + + if a.ListenHTTP != 0 { + wg.Add(1) + go func() { + defer wg.Done() + err := listenAndServe(a.ListenHTTP, a.ServeHTTP, nil) + if err != nil { + log.Fatal(err) + } + }() + } + + // Listen for HTTPS + if a.ListenHTTPS != 0 { + wg.Add(1) + go func() { + defer wg.Done() + err := listenAndServeTLS(a.ListenHTTPS, a.RootCertificate, a.RootKey, a.ServeHTTP, a.ServeTLS) + if err != nil { + log.Fatal(err) + } + }() + } + + // Listen for HTTP proxy requests + if a.listenProxy != 0 { + wg.Add(1) + go func() { + defer wg.Done() + err := listenAndServe(a.listenProxy, a.ServeProxy, nil) + if err != nil { + log.Fatal(err) + } + }() + } + + go watchDomains(a.UpdateDomains, time.Second) + + wg.Wait() +} |