Skip to content

Commit aaf2453

Browse files
Merge pull request #138 from OutSystems/RDGRS-1189
feat(RDGRS-1189): added the client version to the User-Agent header
2 parents d1f6379 + 3aacc13 commit aaf2453

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

.goreleaser.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ builds:
1111
- env:
1212
- CGO_ENABLED=0
1313
goos:
14-
- linux
14+
- linux
15+
ldflags:
16+
- "-s -w -X main.version={{ .Version }}"
1517
dockers:
1618
- image_templates:
1719
- "ghcr.io/outsystems/{{ .ProjectName }}:{{ .Version }}"

main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"net/http"
98
"os"
@@ -31,7 +30,7 @@ func main() {
3130

3231
func generatePidFile() {
3332
pid := []byte(strconv.Itoa(os.Getpid()))
34-
if err := ioutil.WriteFile("outsystemscc.pid", pid, 0644); err != nil {
33+
if err := os.WriteFile("outsystemscc.pid", pid, 0644); err != nil {
3534
log.Fatal(err)
3635
}
3736
}
@@ -51,7 +50,7 @@ func (flag *headerFlags) String() string {
5150
func (flag *headerFlags) Set(arg string) error {
5251
index := strings.Index(arg, ":")
5352
if index < 0 {
54-
return fmt.Errorf(`Invalid header (%s). Should be in the format "HeaderName: HeaderContent"`, arg)
53+
return fmt.Errorf(`invalid header (%s). Should be in the format "HeaderName: HeaderContent"`, arg)
5554
}
5655
if flag.Header == nil {
5756
flag.Header = http.Header{}
@@ -139,6 +138,12 @@ func client(args []string) {
139138
os.Exit(0)
140139
}
141140
flags.Parse(args)
141+
142+
// Set custom User-Agent
143+
if config.Headers.Get("User-Agent") == "" {
144+
config.Headers.Set("User-Agent", fmt.Sprintf("CloudConnector/%s", version))
145+
}
146+
142147
//pull out options, put back remaining args
143148
args = flags.Args()
144149
if len(args) < 2 {

0 commit comments

Comments
 (0)