diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 21:21:21 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 21:21:21 +0300 |
commit | 3824fc8ca34b8f94ae7ef7550aec196dbbfdecf5 (patch) | |
tree | 87232d79817efbfc51cef62d6cf37e38d51d7d6d /app.go | |
parent | ab00ebdb114513eb3c77b6b45c5adf7848b1fc87 (diff) |
Move most of configuration to appConfig
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() +} |