reorder some source files
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package gcrcli
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RoundTripper struct {
|
||||
skipTLSVerify bool
|
||||
}
|
||||
|
||||
func NewRoundTripper(skipTLSVerify bool) *RoundTripper {
|
||||
return &RoundTripper{
|
||||
skipTLSVerify: skipTLSVerify,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *RoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: t.skipTLSVerify,
|
||||
}
|
||||
httpTransport := &http.Transport{
|
||||
TLSClientConfig: tlsConfig,
|
||||
}
|
||||
return httpTransport.RoundTrip(r)
|
||||
}
|
||||
|
||||
func repackReference(ref string) (string, string, string, error) {
|
||||
var err error
|
||||
var username string
|
||||
var password string
|
||||
if !strings.Contains(ref, `://`) {
|
||||
ref = "https://" + ref
|
||||
}
|
||||
uri, err := url.Parse(ref)
|
||||
if err != nil {
|
||||
return ref, username, password, err
|
||||
}
|
||||
username = uri.User.Username()
|
||||
password, _ = uri.User.Password()
|
||||
uri.User = nil
|
||||
|
||||
uri.Path, _ = url.JoinPath("/", uri.Path)
|
||||
if err != nil {
|
||||
return ref, username, password, err
|
||||
}
|
||||
ref = uri.Host + uri.Path
|
||||
return ref, username, password, err
|
||||
}
|
||||
|
||||
func repackSource(ref string) (string, string, string, error) {
|
||||
var err error
|
||||
var username string
|
||||
var password string
|
||||
if !strings.Contains(ref, `://`) {
|
||||
ref = "https://" + ref
|
||||
}
|
||||
uri, err := url.Parse(ref)
|
||||
if err != nil {
|
||||
return ref, username, password, err
|
||||
}
|
||||
username = uri.User.Username()
|
||||
password, _ = uri.User.Password()
|
||||
uri.User = nil
|
||||
|
||||
ref = uri.Host
|
||||
return ref, username, password, err
|
||||
}
|
||||
Reference in New Issue
Block a user