Skip to content

Commit 6cba5be

Browse files
Merge pull request #8 from cloudfoundry-community/devel
upgrade go and dependencies
2 parents 4c7a340 + 2397f63 commit 6cba5be

File tree

8 files changed

+85
-26
lines changed

8 files changed

+85
-26
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
12+
# pull-requests: read
13+
14+
jobs:
15+
golangci:
16+
name: lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: '>=1.22'
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v6
25+
with:
26+
version: v1.58

.github/workflows/unit-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: unit-tests
2+
3+
on:
4+
pull_request: ~
5+
push: ~
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: set up go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: "1.22"
20+
21+
- name: cache go modules
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/go/pkg/mod
25+
key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}"
26+
restore-keys: |
27+
${{ runner.os }}-go-
28+
29+
- name: tests
30+
run: |
31+
go test -v ./...

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package clients
22

3-
// config -
3+
// Config -
44
type Config struct {
55
// Cloud foundry api endoint
66
Endpoint string

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/cloudfoundry-community/go-cf-clients-helper/v2
22

3-
go 1.21
4-
5-
toolchain go1.21.5
3+
go 1.22.3
64

75
exclude (
86
github.com/imdario/mergo v0.3.16

rawclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type RawClientConfig struct {
3131
ApiEndpoint string
3232
}
3333

34-
// Raw http client has uaa client authentication to make raw request with golang native api.
34+
// RawClient Raw http client has uaa client authentication to make raw request with golang native api.
3535
type RawClient struct {
3636
connection cloudcontroller.Connection
3737
apiEndpoint string

requestlogger.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,23 @@ func NewRequestLogger() *RequestLogger {
9898
}
9999

100100
func (display *RequestLogger) DisplayBody([]byte) error {
101-
log.Print(fmt.Sprintf("%s\n", RedactedValue))
101+
log.Printf("%s\n", RedactedValue)
102102
return nil
103103
}
104104

105105
func (display *RequestLogger) DisplayDump(dump string) error {
106106
sanitized := display.dumpSanitizer.ReplaceAllString(dump, RedactedValue)
107-
log.Print(fmt.Sprintf("%s\n", sanitized))
107+
log.Printf("%s\n", sanitized)
108108
return nil
109109
}
110110

111111
func (display *RequestLogger) DisplayHeader(name string, value string) error {
112-
log.Print(fmt.Sprintf("%s: %s\n", name, value))
112+
log.Printf("%s: %s\n", name, value)
113113
return nil
114114
}
115115

116116
func (display *RequestLogger) DisplayHost(name string) error {
117-
log.Print(fmt.Sprintf("host: %s\n", name))
117+
log.Printf("host: %s\n", name)
118118
return nil
119119
}
120120

@@ -125,27 +125,27 @@ func (display *RequestLogger) DisplayJSONBody(body []byte) error {
125125

126126
sanitized, err := SanitizeJSON(body)
127127
if err != nil {
128-
log.Print(fmt.Sprintf("%s\n", string(body)))
128+
log.Printf("%s\n", string(body))
129129
return nil
130130
}
131131

132-
log.Print(fmt.Sprintf("%s\n", string(sanitized)))
132+
log.Printf("%s\n", string(sanitized))
133133

134134
return nil
135135
}
136136

137137
func (display *RequestLogger) DisplayMessage(msg string) error {
138-
log.Print(fmt.Sprintf("%s\n", msg))
138+
log.Printf("%s\n", msg)
139139
return nil
140140
}
141141

142142
func (display *RequestLogger) DisplayRequestHeader(method string, uri string, httpProtocol string) error {
143-
log.Print(fmt.Sprintf("%s %s %s\n", method, uri, httpProtocol))
143+
log.Printf("%s %s %s\n", method, uri, httpProtocol)
144144
return nil
145145
}
146146

147147
func (display *RequestLogger) DisplayResponseHeader(httpProtocol string, status string) error {
148-
log.Print(fmt.Sprintf("%s %s\n", httpProtocol, status))
148+
log.Printf("%s %s\n", httpProtocol, status)
149149
return nil
150150
}
151151

retrywrapper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"code.cloudfoundry.org/cli/api/cloudcontroller"
66
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
77
"code.cloudfoundry.org/cli/api/router"
8+
"errors"
89
"io"
9-
"io/ioutil"
1010
"net/http"
1111
"reflect"
1212
)
@@ -46,7 +46,7 @@ func (retry *RetryRequest) Make(request *cloudcontroller.Request, passedResponse
4646

4747
// detect if body is ioutil.NopCloser(&bytes.Buffer)
4848
// if so we reset the content the buffer to be able to redo request with same body
49-
if reflect.TypeOf(request.Body) == reflect.TypeOf(ioutil.NopCloser) {
49+
if reflect.TypeOf(request.Body) == reflect.TypeOf(io.NopCloser) {
5050
reader := reflect.ValueOf(request.Body).FieldByName("Reader")
5151
if buf, ok := reader.Interface().(*bytes.Buffer); ok {
5252
data := buf.Bytes()
@@ -60,7 +60,8 @@ func (retry *RetryRequest) Make(request *cloudcontroller.Request, passedResponse
6060
if reader, ok := request.Body.(io.ReadSeeker); ok {
6161
_, resetErr := reader.Seek(0, 0)
6262
if resetErr != nil {
63-
if _, ok := resetErr.(ccerror.PipeSeekError); ok {
63+
var pipeSeekError ccerror.PipeSeekError
64+
if errors.As(resetErr, &pipeSeekError) {
6465
return ccerror.PipeSeekError{Err: err}
6566
}
6667
return resetErr
@@ -117,7 +118,7 @@ func (retry *retryRequestRouter) Make(request *router.Request, passedResponse *r
117118
}
118119
// detect if body is ioutil.NopCloser(&bytes.Buffer)
119120
// if so we reset the content the buffer to be able to redo request with same body
120-
if reflect.TypeOf(request.Body) == reflect.TypeOf(ioutil.NopCloser) {
121+
if reflect.TypeOf(request.Body) == reflect.TypeOf(io.NopCloser) {
121122
reader := reflect.ValueOf(request.Body).FieldByName("Reader")
122123
if buf, ok := reader.Interface().(*bytes.Buffer); ok {
123124
data := buf.Bytes()
@@ -131,7 +132,8 @@ func (retry *retryRequestRouter) Make(request *router.Request, passedResponse *r
131132
if reader, ok := request.Body.(io.ReadSeeker); ok {
132133
_, resetErr := reader.Seek(0, 0)
133134
if resetErr != nil {
134-
if _, ok := resetErr.(ccerror.PipeSeekError); ok {
135+
var pipeSeekError ccerror.PipeSeekError
136+
if errors.As(resetErr, &pipeSeekError) {
135137
return ccerror.PipeSeekError{Err: err}
136138
}
137139
return resetErr

session.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,32 @@ func NewSession(c Config) (s *Session, err error) {
8585
return s, nil
8686
}
8787

88-
// Give access to api cf v3 (complete and always up to date, thanks to cli v7 team)
88+
// V3 Give access to api cf v3 (complete and always up to date, thanks to cli v7 team)
8989
func (s *Session) V3() *ccv3.Client {
9090
return s.clientV3
9191
}
9292

93-
// Give access to api uaa (incomplete)
93+
// UAA Give access to api uaa (incomplete)
9494
func (s *Session) UAA() *uaa.Client {
9595
return s.clientUAA
9696
}
9797

98-
// Give access to TCP Routing api
98+
// TCPRouter Give access to TCP Routing api
9999
func (s *Session) TCPRouter() *router.Client {
100100
return s.routerClient
101101
}
102102

103-
// Give access to networking policy api
103+
// Networking Give access to networking policy api
104104
func (s *Session) Networking() *cfnetv1.Client {
105105
return s.netClient
106106
}
107107

108-
// Give an http client which pass authorization header to call api(s) directly
108+
// Raw Give an http client which pass authorization header to call api(s) directly
109109
func (s *Session) Raw() *RawClient {
110110
return s.rawClient
111111
}
112112

113-
// Give config store for client which need access token
113+
// ConfigStore Give config store for client which need access token
114114
func (s *Session) ConfigStore() *configv3.Config {
115115
return s.configStore
116116
}
@@ -146,7 +146,9 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
146146
// create an uaa client with cf_username/cf_password or client_id/client secret
147147
// to use it for authenticate requests
148148
uaaClient := uaa.NewClient(config)
149-
uaaClient.GetAPIVersion()
149+
if _, err := uaaClient.GetAPIVersion(); err != nil {
150+
return fmt.Errorf("unable to get API version: %s", err)
151+
}
150152

151153
uaaAuthWrapper := uaaWrapper.NewUAAAuthentication(nil, configUaa)
152154
uaaClient.WrapConnection(uaaAuthWrapper)

0 commit comments

Comments
 (0)