forked from labd/commercetools-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_useragent.go
41 lines (36 loc) · 1.12 KB
/
client_useragent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package commercetools
import (
"fmt"
"runtime"
"strings"
)
// GetUserAgent determines the user agent for all HTTP requests.
func GetUserAgent(cfg *ClientConfig) string {
baseInfo := fmt.Sprintf("commercetools-go-sdk/%s", Version)
systemInfo := fmt.Sprintf("Go/%s (%s; %s)", runtime.Version(), runtime.GOOS, runtime.GOARCH)
libraryInfo := ""
if cfg.LibraryName != "" && cfg.LibraryVersion == "" {
libraryInfo = cfg.LibraryName
} else if cfg.LibraryName != "" && cfg.LibraryVersion != "" {
libraryInfo = fmt.Sprintf("%s/%s", cfg.LibraryName, cfg.LibraryVersion)
}
contactInfo := ""
if cfg.ContactURL != "" && cfg.ContactEmail == "" {
contactInfo = fmt.Sprintf("(+%s)", cfg.ContactURL)
} else if cfg.ContactURL == "" && cfg.ContactEmail != "" {
contactInfo = fmt.Sprintf("(+%s)", cfg.ContactEmail)
} else if cfg.ContactURL != "" && cfg.ContactEmail != "" {
contactInfo = fmt.Sprintf("(+%s; +%s)", cfg.ContactURL, cfg.ContactEmail)
}
s := []string{
baseInfo,
systemInfo,
}
if libraryInfo != "" {
s = append(s, libraryInfo)
}
if contactInfo != "" {
s = append(s, contactInfo)
}
return strings.Join(s, " ")
}