MCPcopy
hub / github.com/benbjohnson/litestream / ParseReplicaURLWithQuery

Function ParseReplicaURLWithQuery

replica_url.go:79–104  ·  view source on GitHub ↗

ParseReplicaURLWithQuery parses a replica URL and returns query parameters and userinfo.

(s string)

Source from the content-addressed store, hash-verified

77
78// ParseReplicaURLWithQuery parses a replica URL and returns query parameters and userinfo.
79func ParseReplicaURLWithQuery(s string) (scheme, host, urlPath string, query url.Values, userinfo *url.Userinfo, err error) {
80 // Handle S3 Access Point ARNs which can't be parsed by standard url.Parse
81 if strings.HasPrefix(strings.ToLower(s), "s3://arn:") {
82 scheme, host, urlPath, query, err := parseS3AccessPointURL(s)
83 return scheme, host, urlPath, query, nil, err
84 }
85
86 u, err := url.Parse(s)
87 if err != nil {
88 return "", "", "", nil, nil, err
89 }
90
91 switch u.Scheme {
92 case "file":
93 scheme, u.Scheme = u.Scheme, ""
94 // Remove query params from path for file URLs
95 u.RawQuery = ""
96 return scheme, "", path.Clean(u.String()), nil, nil, nil
97
98 case "":
99 return u.Scheme, u.Host, u.Path, nil, nil, fmt.Errorf("replica url scheme required: %s", s)
100
101 default:
102 return u.Scheme, u.Host, strings.TrimPrefix(path.Clean(u.Path), "/"), u.Query(), u.User, nil
103 }
104}
105
106// parseS3AccessPointURL parses an S3 Access Point URL (s3://arn:...).
107func parseS3AccessPointURL(s string) (scheme, host, urlPath string, query url.Values, err error) {

Callers 4

NewReplicaClientFromURLFunction · 0.85
ParseReplicaURLFunction · 0.85

Calls 2

parseS3AccessPointURLFunction · 0.85
StringMethod · 0.45

Tested by 1