diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-24 15:52:07 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-24 15:52:38 +0300 |
commit | bfbfb6259e7c875f053b49aaf430a1c4db7a1e9f (patch) | |
tree | 55953b3e6570f413f3c25db830a4f4ce043fff5a | |
parent | 697818eb287e1ba4e0010e0074d132896629ba64 (diff) |
Improve code quality and add a few missing comments
-rw-r--r-- | internal/domain/domain.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/serving.go | 4 | ||||
-rw-r--r-- | internal/serving/request.go | 2 | ||||
-rw-r--r-- | internal/source/domains.go | 9 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 2 |
5 files changed, 17 insertions, 2 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go index 9ac668a5..a1ee896e 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -40,6 +40,8 @@ func (d *Domain) isUnconfigured() bool { func (d *Domain) resolve(r *http.Request) *serving.Request { request, _ := d.Resolver.Resolve(r) + // TODO improve code around default serving, when `disk` serving gets removed + // https://gitlab.com/gitlab-org/gitlab-pages/issues/353 if request == nil { return &serving.Request{Serving: disk.New()} } diff --git a/internal/serving/disk/serving.go b/internal/serving/disk/serving.go index 430aa95f..9182da75 100644 --- a/internal/serving/disk/serving.go +++ b/internal/serving/disk/serving.go @@ -7,6 +7,10 @@ import ( var disk *Disk +func init() { + disk = &Disk{} +} + // Disk describes a disk access serving type Disk struct { Reader diff --git a/internal/serving/request.go b/internal/serving/request.go index 1658af62..694d0df4 100644 --- a/internal/serving/request.go +++ b/internal/serving/request.go @@ -5,7 +5,7 @@ import "net/http" // Request is a type that aggregates a serving itself, project lookup path and // a request subpath based on an incoming request to serve page. type Request struct { - Serving Serving // Serving choosen to serve this request + Serving Serving // Serving chosen to serve this request LookupPath *LookupPath // LookupPath contains pages project details SubPath string // Subpath is a URL path subcomponent for this request } diff --git a/internal/source/domains.go b/internal/source/domains.go index b70b59e6..c3c4b5fe 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -82,6 +82,9 @@ func (d *Domains) source(domain string) Source { return d.disk } + // This check is only needed until we enable `d.gitlab` source in all + // environments (including on-premises installations) followed by removal of + // `d,disk` source. This can be safely removed afterwards. if IsServerlessDomain(domain) { return d.gitlab } @@ -108,7 +111,11 @@ func (d *Domains) source(domain string) Source { } // IsServerlessDomain checks if a domain requested is a serverless domain we -// need to handle differently +// need to handle differently. +// +// Domain is a serverless domain when it matches `serverlessDomainRegex`. The +// regular expression is also defined on the gitlab-rails side, see +// https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/serverless/domain.rb#L7 func IsServerlessDomain(domain string) bool { return serverlessDomainRegex.MatchString(domain) } diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index 299c5acb..7accac0c 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -89,6 +89,8 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { } } + // TODO improve code around default serving, when `disk` serving gets removed + // https://gitlab.com/gitlab-org/gitlab-pages/issues/353 return &serving.Request{Serving: factory.DefaultServing()}, errors.New("could not match lookup path") } |