Skip to content

Commit 6cca756

Browse files
committed
sdk changes
1 parent 5e5bb4d commit 6cca756

File tree

7 files changed

+103186
-2
lines changed

7 files changed

+103186
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package common
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
7+
8+
const (
9+
HEADER_NAME_USER_AGENT = "User-Agent"
10+
11+
SDK_NAME = "go-sdk-template"
12+
)
13+
14+
//
15+
// GetSdkHeaders - returns the set of SDK-specific headers to be included in an outgoing request.
16+
//
17+
// This function is invoked by generated service methods (i.e. methods which implement the REST API operations
18+
// defined within the API definition). The purpose of this function is to give the SDK implementor the opportunity
19+
// to provide SDK-specific HTTP headers that will be sent with an outgoing REST API request.
20+
// This function is invoked for each invocation of a generated service method,
21+
// so the set of HTTP headers could be request-specific.
22+
// As an optimization, if your SDK will be returning the same set of HTTP headers for each invocation of this
23+
// function, it is recommended that you initialize the returned map just once (perhaps by using
24+
// lazy initialization) and simply return it each time the function is invoked, instead of building it each time
25+
// as in the example below.
26+
//
27+
// Parameters:
28+
// serviceName - the name of the service as defined in the API definition (e.g. "MyService1")
29+
// serviceVersion - the version of the service as defined in the API definition (e.g. "V1")
30+
// operationId - the operationId as defined in the API definition (e.g. getContext)
31+
//
32+
// Returns:
33+
// a Map which contains the set of headers to be included in the REST API request
34+
//
35+
func GetSdkHeaders(serviceName string, serviceVersion string, operationId string) map[string]string {
36+
sdkHeaders := make(map[string]string)
37+
38+
sdkHeaders[HEADER_NAME_USER_AGENT] = GetUserAgentInfo()
39+
40+
return sdkHeaders
41+
}
42+
43+
var userAgent string = fmt.Sprintf("%s-%s %s", SDK_NAME, Version, GetSystemInfo())
44+
45+
func GetUserAgentInfo() string {
46+
return userAgent
47+
}
48+
49+
var systemInfo = fmt.Sprintf("(arch=%s; os=%s; go.version=%s)", runtime.GOARCH, runtime.GOOS, runtime.Version())
50+
51+
func GetSystemInfo() string {
52+
return systemInfo
53+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package common
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestGetSystemInfo(t *testing.T) {
10+
var sysinfo = GetSystemInfo()
11+
assert.NotNil(t, sysinfo)
12+
assert.True(t, strings.Contains(sysinfo, "arch="))
13+
assert.True(t, strings.Contains(sysinfo, "os="))
14+
assert.True(t, strings.Contains(sysinfo, "go.version="))
15+
}
16+
17+
func TestGetSdkHeaders(t *testing.T) {
18+
var headers = GetSdkHeaders("myService", "v123", "myOperation")
19+
assert.NotNil(t, headers)
20+
21+
var foundIt bool
22+
23+
_, foundIt = headers[HEADER_NAME_USER_AGENT]
24+
assert.True(t, foundIt)
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package common
2+
3+
// Version of the SDK
4+
const Version = "0.0.1"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// module github.com/IBM-Cloud/terraform-provider-ibm/vendor/github.com/softlayer/softlayer-go
2+
module github.com/IBM/vpc-go-sdk
3+
4+
go 1.12
5+
6+
// replace github.com/IBM/vpc-go-sdk/common => ./common/github.com/IBM/vpc-go-sdk/common

0 commit comments

Comments
 (0)