Skip to content

Commit

Permalink
Merge pull request #66 from orange-cloudfoundry/upgrade-to-go1.21
Browse files Browse the repository at this point in the history
Upgrade to go1.21
  • Loading branch information
romain-dartigues authored Sep 12, 2023
2 parents e50a2e7 + e22da57 commit 9a000fe
Show file tree
Hide file tree
Showing 42 changed files with 54,141 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: goreleaser

on:
push:
# not not consider simplec commit
# do not consider simple commit
branches:
- '!*'
# consider only release and pre-release tags
Expand All @@ -22,7 +22,7 @@ jobs:
- name: set up go
uses: actions/setup-go@v2
with:
go-version: ">=1.20"
go-version: ">=1.21"

- name: cache go modules
uses: actions/cache@v1
Expand All @@ -36,7 +36,7 @@ jobs:
run: |
go mod vendor
if [ ! -z "$(git status --porcelain)" ]; then
echo "::error::vendor directory if not synched with go.mod, please run go mod vendor"
echo "::error::vendor directory if not synced with go.mod, please run go mod vendor"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: set up go
uses: actions/setup-go@v2
with:
go-version: 1.20
go-version: 1.21

- name: cache go modules
uses: actions/cache@v1
Expand Down
5 changes: 2 additions & 3 deletions aggregate_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (a AggregateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {

var previousData []byte
if req.Body != nil {
previousData, _ = ioutil.ReadAll(req.Body)
previousData, _ = io.ReadAll(req.Body)
}

for _, endpoint := range endpoints {
Expand Down Expand Up @@ -168,7 +167,7 @@ func (a AggregateHandler) aggregateFromEndpoint(reqEndpoint *http.Request, endpo
}

defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
// 2.
syncMap.Store(
Expand Down
11 changes: 5 additions & 6 deletions aggregate_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/orange-cloudfoundry/aggregadantur/contexes"
"github.com/orange-cloudfoundry/aggregadantur/models"
"github.com/orange-cloudfoundry/aggregadantur/testhelper"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
)
Expand Down Expand Up @@ -48,7 +48,6 @@ var _ = Describe("AggregateHandler", func() {
models.Auth{},
models.PathMatchers{models.NewPathMatcher("/**")},
models.PathMatchers{models.NewPathMatcher("/metrics")},

)

Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -115,7 +114,7 @@ var _ = Describe("AggregateHandler", func() {
Expect(res["test3"]).To(Equal("test3"))
})
When("aggregator_targets is set", func() {
It("should give all targets targetted and not more", func() {
It("should give all targets targeted and not more", func() {
req := testhelper.NewRequest(http.MethodGet, "http://localhost/aggregate", nil)
req.Header.Set(aggregadantur.XAggregatorModeHeader, string(aggregadantur.AggregateModeDefault))
req.Header.Set(aggregadantur.XAggregatorTargetsHeader, "test2,test3")
Expand Down Expand Up @@ -215,21 +214,21 @@ var _ = Describe("AggregateHandler", func() {

upstreamHandler.SetFn(func(w http.ResponseWriter, req *http.Request) bool {
defer GinkgoRecover()
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(b)).To(Equal("send data"))
return false
})
test2Pack.Handler().SetFn(func(w http.ResponseWriter, req *http.Request) bool {
defer GinkgoRecover()
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(b)).To(Equal("send data"))
return false
})
test3Pack.Handler().SetFn(func(w http.ResponseWriter, req *http.Request) bool {
defer GinkgoRecover()
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(b)).To(Equal("send data"))
return false
Expand Down
9 changes: 5 additions & 4 deletions auth_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"github.com/orange-cloudfoundry/aggregadantur/contexes"
"github.com/orange-cloudfoundry/aggregadantur/jwtclaim"
"github.com/orange-cloudfoundry/aggregadantur/models"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -137,7 +138,7 @@ func (a AuthHandler) loginPage(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(makeLoginPageHtml(
loginPageTemplate,
strings.Title(a.aggrRoute.Name),
cases.Title(language.AmericanEnglish).String(a.aggrRoute.Name),
redirectUrl,
)))
return
Expand Down Expand Up @@ -249,10 +250,10 @@ func (a AuthHandler) oauth2Auth(origReq *http.Request) (AccessTokenResponse, err
if resp.StatusCode == 401 || resp.StatusCode == 403 {
return AccessTokenResponse{}, fmt.Errorf("%d: Unauthorized on uaa", resp.StatusCode)
}
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
return AccessTokenResponse{}, fmt.Errorf("from oauth server %d: %s", resp.StatusCode, string(b))
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return AccessTokenResponse{}, fmt.Errorf("when getting token for %s: %s", user, err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions auth_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var _ = Describe("AuthHandler", func() {
Expect(respRecorder.Header().Get("Location")).To(Equal("/"))
})

It("should sunauthorized if user is incorrect", func() {
It("should be unauthorized if user is incorrect", func() {
form := url.Values{}
form.Add("username", "user")
form.Add("password", "password")
Expand All @@ -165,7 +165,7 @@ var _ = Describe("AuthHandler", func() {
})
})
Context("Token jwt is given", func() {
It("should pass request and apply headers and contexes in request if token is correct", func() {
It("should pass request and apply headers and contexts in request if token is correct", func() {
req := testhelper.NewRequest(http.MethodGet, "http://localhost", nil)
req.Header.Set("Authorization", "Bearer "+jwtToken)

Expand All @@ -183,14 +183,14 @@ var _ = Describe("AuthHandler", func() {
})
It("should unauthorized if token is incorrect", func() {
req := testhelper.NewRequest(http.MethodGet, "http://localhost", nil)
req.Header.Set("Authorization", "Bearer "+jwtToken+"incorect")
req.Header.Set("Authorization", "Bearer "+jwtToken+"incorrect")

authHandler.ServeHTTP(respRecorder, req)

Expect(respRecorder.Code).To(Equal(http.StatusUnauthorized))
})
When("token is in session", func() {
It("should pass request and apply headers and contexes in request if token is correct", func() {
It("should pass request and apply headers and contexts in request if token is correct", func() {
req := testhelper.NewRequest(http.MethodGet, "http://localhost", nil)
sess, err := store.Get(req, "auth-test")
Expect(err).ToNot(HaveOccurred())
Expand Down
3 changes: 1 addition & 2 deletions cmd/aggregadantur/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/orange-cloudfoundry/aggregadantur/models"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -75,7 +74,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

func GetConfig(configPath string) (Config, error) {
b, err := ioutil.ReadFile(configPath)
b, err := os.ReadFile(configPath)
if err != nil {
return Config{}, err
}
Expand Down
1 change: 0 additions & 1 deletion forward_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func createReverseHandler(proxyRoute *models.AggregateRoute) (http.Handler, erro
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
Expand Down
4 changes: 2 additions & 2 deletions forward_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/orange-cloudfoundry/aggregadantur/models"
"github.com/orange-cloudfoundry/aggregadantur/testhelper"
log "github.com/sirupsen/logrus"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -20,7 +20,7 @@ var _ = Describe("ForwardHandler", func() {
var aggrRoute *models.AggregateRoute
var fwdHandler *aggregadantur.ForwardHandler
BeforeEach(func() {
log.StandardLogger().Out = ioutil.Discard
log.StandardLogger().Out = io.Discard
var err error
respRecorder = httptest.NewRecorder()
pack = NewAggregateEndpointPack("test")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/prometheus/common v0.44.0
github.com/sirupsen/logrus v1.9.3
github.com/vulcand/oxy v1.4.2
golang.org/x/text v0.10.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -41,7 +42,6 @@ require (
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
1 change: 0 additions & 1 deletion models/aggregate_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var _ = Describe("AggregateRoute", func() {
models.Auth{},
models.PathMatchers{models.NewPathMatcher("/**")},
models.PathMatchers{models.NewPathMatcher("/metrics")},

)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
4 changes: 2 additions & 2 deletions models/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package models
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

func NewAuthWithOauth2(
Expand Down Expand Up @@ -40,7 +40,7 @@ func (a Auth) MakeLoginPageTemplate(defaultTemplate string) (string, error) {
if a.LoginPageTemplatePath == "" {
return defaultTemplate, nil
}
b, err := ioutil.ReadFile(a.LoginPageTemplatePath)
b, err := os.ReadFile(a.LoginPageTemplatePath)
if err != nil {
return "", err
}
Expand Down
1 change: 0 additions & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func makeHttpClient(skipSSLValidation bool) *http.Client {
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
Expand Down
1 change: 1 addition & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

package tools
Expand Down
Loading

0 comments on commit 9a000fe

Please sign in to comment.