• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gophercloud / gophercloud / 15559696175

10 Jun 2025 12:38PM UTC coverage: 63.628% (-0.1%) from 63.748%
15559696175

push

github

web-flow
Merge pull request #3351 from stephenfin/endpoint-discovery

Add versioned endpoint discovery

65 of 166 new or added lines in 5 files covered. (39.16%)

23408 of 36789 relevant lines covered (63.63%)

98.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.57
/openstack/utils/base_endpoint.go
1
package utils
2

3
import (
4
        "net/url"
5
        "regexp"
6
        "strings"
7
)
8

9
func parseEndpoint(endpoint string, includeVersion bool) (string, error) {
100✔
10
        u, err := url.Parse(endpoint)
100✔
11
        if err != nil {
100✔
12
                return "", err
×
13
        }
×
14

15
        u.RawQuery, u.Fragment = "", ""
100✔
16

100✔
17
        path := u.Path
100✔
18
        versionRe := regexp.MustCompile("v[0-9.]+/?")
100✔
19

100✔
20
        if version := versionRe.FindString(path); version != "" {
134✔
21
                versionIndex := strings.Index(path, version)
34✔
22
                if includeVersion {
34✔
NEW
23
                        versionIndex += len(version)
×
NEW
24
                }
×
25
                u.Path = path[:versionIndex]
34✔
26
        }
27

28
        return u.String(), nil
100✔
29
}
30

31
// BaseEndpoint will return a URL without the /vX.Y
32
// portion of the URL.
33
func BaseEndpoint(endpoint string) (string, error) {
100✔
34
        return parseEndpoint(endpoint, false)
100✔
35
}
100✔
36

37
// BaseVersionedEndpoint will return a URL with the /vX.Y portion of the URL,
38
// if present, but without a project ID or similar
NEW
39
func BaseVersionedEndpoint(endpoint string) (string, error) {
×
NEW
40
        return parseEndpoint(endpoint, true)
×
NEW
41
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc