diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-02-28 21:25:01 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-02-28 21:25:01 +0300 |
commit | 6e3da2c0815b4d3af243bc5ddfdc24efb3846184 (patch) | |
tree | 6ca1a56a5abac51bd9765a82751403a5fc30e93f /internal/client | |
parent | 4bb60040d5abc2478ffafac5afe308ef7b04cb25 (diff) |
Fix comments
Diffstat (limited to 'internal/client')
-rw-r--r-- | internal/client/api.go | 7 | ||||
-rw-r--r-- | internal/client/domain_response.go | 3 | ||||
-rw-r--r-- | internal/client/lookup_path.go | 3 | ||||
-rw-r--r-- | internal/client/mock_api.go | 6 |
4 files changed, 15 insertions, 4 deletions
diff --git a/internal/client/api.go b/internal/client/api.go index cd10283f..f3657a80 100644 --- a/internal/client/api.go +++ b/internal/client/api.go @@ -6,12 +6,15 @@ import ( "net/url" ) -func RequestDomain(apiUrl, host string) *DomainResponse { +// RequestDomain requests the configuration of domain from GitLab +// this provides information where to fetch data from in order to serve +// the domain content +func RequestDomain(apiURL, host string) *DomainResponse { values := url.Values{ "host": []string{host}, } - resp, err := http.PostForm(apiUrl+"/pages/domain", values) + resp, err := http.PostForm(apiURL+"/pages/domain", values) if err != nil { // Ignore error, or print it return nil diff --git a/internal/client/domain_response.go b/internal/client/domain_response.go index 1b91ef49..32a2ce47 100644 --- a/internal/client/domain_response.go +++ b/internal/client/domain_response.go @@ -5,6 +5,8 @@ import ( "strings" ) +// DomainResponse describes a configuration for domain, +// like certificate, but also lookup paths to serve the content type DomainResponse struct { Certificate string `json:"certificate"` Key string `json:"certificate_key"` @@ -12,6 +14,7 @@ type DomainResponse struct { LookupPath []LookupPath `json:"lookup_paths"` } +// GetPath finds a first matching lookup path that should serve the content func (d *DomainResponse) GetPath(path string) (*LookupPath, error) { for _, lp := range d.LookupPath { if strings.HasPrefix(path, lp.Prefix) || path+"/" == lp.Prefix { diff --git a/internal/client/lookup_path.go b/internal/client/lookup_path.go index 41d79063..0ba3fc2f 100644 --- a/internal/client/lookup_path.go +++ b/internal/client/lookup_path.go @@ -4,6 +4,8 @@ import ( "strings" ) +// LookupPath describes a single mapping between HTTP Prefix +// and actual data on disk type LookupPath struct { Prefix string `json:"prefix"` Path string `json:"path"` @@ -14,6 +16,7 @@ type LookupPath struct { ProjectID uint64 `json:"id"` } +// Tail returns a relative path to full path to serve the content func (lp *LookupPath) Tail(path string) string { if strings.HasPrefix(path, lp.Prefix) { return path[len(lp.Prefix):] diff --git a/internal/client/mock_api.go b/internal/client/mock_api.go index 6159a212..bf738f96 100644 --- a/internal/client/mock_api.go +++ b/internal/client/mock_api.go @@ -257,10 +257,12 @@ var internalConfigs = map[string]DomainResponse{ }, } -func MockRequestDomain(apiUrl, host string) *DomainResponse { +// MockRequestDomain provides a preconfigured set of domains +// for testing purposes +func MockRequestDomain(apiURL, host string) *DomainResponse { if response, ok := internalConfigs[host]; ok { - println("Requested", host) return &response } + return nil } |