-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(httpclientx): use better naming
Prodded by @ainghazal to avoid confusion when discussing.
- Loading branch information
1 parent
f10bad6
commit c369bb3
Showing
29 changed files
with
183 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package httpclientx | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/model" | ||
|
||
// BaseURL is an HTTP-endpoint base URL. | ||
// | ||
// The zero value is invalid; construct using [NewBaseURL]. | ||
type BaseURL struct { | ||
// Value is the MANDATORY base-URL Value. | ||
Value string | ||
|
||
// HostOverride is the OPTIONAL host header to use for cloudfronting. | ||
HostOverride string | ||
} | ||
|
||
// NewBaseURL constructs a new [*BaseURL] instance using the given URL. | ||
func NewBaseURL(URL string) *BaseURL { | ||
return &BaseURL{ | ||
Value: URL, | ||
HostOverride: "", | ||
} | ||
} | ||
|
||
// WithHostOverride returns a copy of the [*BaseURL] using the given host header override. | ||
func (e *BaseURL) WithHostOverride(host string) *BaseURL { | ||
return &BaseURL{ | ||
Value: e.Value, | ||
HostOverride: host, | ||
} | ||
} | ||
|
||
// NewBaseURLsFromModelOOAPIServices constructs new [*BaseURL] instances from the | ||
// given [model.OOAPIService] instances, assigning the host header if "cloudfront", and | ||
// skipping all the entries that are neither "https" not "cloudfront". | ||
func NewBaseURLsFromModelOOAPIServices(svcs ...model.OOAPIService) (epnts []*BaseURL) { | ||
for _, svc := range svcs { | ||
epnt := NewBaseURL(svc.Address) | ||
switch svc.Type { | ||
case "cloudfront": | ||
epnt = epnt.WithHostOverride(svc.Front) | ||
fallthrough | ||
case "https": | ||
epnts = append(epnts, epnt) | ||
default: | ||
// skip entry | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.