Skip to content

Commit 72a7115

Browse files
authored
feat: add CI to user-agent for requests (#42)
closes #25
1 parent a15338c commit 72a7115

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"runtime/debug"
1616
"slices"
1717
"sort"
18+
"strconv"
1819
"sync"
1920

2021
"github.com/Masterminds/semver/v3"
@@ -25,8 +26,9 @@ import (
2526
const defaultURL = "https://dbc-cdn.columnar.tech"
2627

2728
var (
28-
baseURL = defaultURL
29-
Version = "unknown"
29+
baseURL = defaultURL
30+
Version = "unknown"
31+
userAgent string
3032
)
3133

3234
func init() {
@@ -38,6 +40,16 @@ func init() {
3840
if val := os.Getenv("DBC_BASE_URL"); val != "" {
3941
baseURL = val
4042
}
43+
44+
userAgent = fmt.Sprintf("dbc-cli/%s (%s; %s)",
45+
Version, runtime.GOOS, runtime.GOARCH)
46+
47+
// many CI systems set CI=true in the env so let's check for that
48+
if ci := os.Getenv("CI"); ci != "" {
49+
if val, _ := strconv.ParseBool(ci); val {
50+
userAgent += " CI"
51+
}
52+
}
4153
}
4254

4355
func makereq(u string) (resp *http.Response, err error) {
@@ -50,8 +62,7 @@ func makereq(u string) (resp *http.Response, err error) {
5062
Method: http.MethodGet,
5163
URL: uri,
5264
Header: http.Header{
53-
"User-Agent": []string{fmt.Sprintf("dbc-cli/%s (%s; %s)",
54-
Version, runtime.GOOS, runtime.GOARCH)},
65+
"User-Agent": []string{userAgent},
5566
},
5667
}
5768

0 commit comments

Comments
 (0)