Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 21:21:21 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 21:21:21 +0300
commit3824fc8ca34b8f94ae7ef7550aec196dbbfdecf5 (patch)
tree87232d79817efbfc51cef62d6cf37e38d51d7d6d /app.go
parentab00ebdb114513eb3c77b6b45c5adf7848b1fc87 (diff)
Move most of configuration to appConfig
Diffstat (limited to 'app.go')
-rw-r--r--app.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/app.go b/app.go
index 08e82042..a3fc8335 100644
--- a/app.go
+++ b/app.go
@@ -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()
+}