From e7b212ef97d378274b36964033aab585be7007bf Mon Sep 17 00:00:00 2001 From: rxj18 Date: Mon, 21 Oct 2024 09:41:29 +0530 Subject: [PATCH] chore: update go version and migrate from io/ioutil to io --- go.mod | 3 ++- go.sum | 2 +- src/go/bank.go | 3 ++- src/go/client.go | 5 +++-- src/go/client_test.go | 5 +++-- src/go/generator/main.go | 16 +++++++--------- src/go/ifsc.go | 5 +++-- src/go/ifsc_test.go | 3 ++- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 2b3da42a..5f1375bf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/razorpay/ifsc/v2 -go 1.18 +go 1.23.2 require github.com/stretchr/testify v1.8.0 @@ -9,3 +9,4 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + diff --git a/go.sum b/go.sum index d7eeeae4..51648299 100644 --- a/go.sum +++ b/go.sum @@ -6,9 +6,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/src/go/bank.go b/src/go/bank.go index 27b1e84d..24093e22 100644 --- a/src/go/bank.go +++ b/src/go/bank.go @@ -17,7 +17,7 @@ type Bank struct { AchCredit bool `json:"ach_credit"` AchDebit bool `json:"ach_debit"` NachDebit bool `json:"nach_debit"` - Upi bool `json:"upi",omitempty` + Upi bool `json:"upi,omitempty"` } var bankData map[string]Bank @@ -45,3 +45,4 @@ func GetBankDetails(bankCode string) *Bank { } return &data } + diff --git a/src/go/client.go b/src/go/client.go index 7e77154c..c929758c 100644 --- a/src/go/client.go +++ b/src/go/client.go @@ -2,7 +2,7 @@ package ifsc import ( "encoding/json" - "io/ioutil" + "io" "log" "net/http" ) @@ -47,7 +47,7 @@ func LookUP(ifsc string) (*IFSCResponse, error) { } status := resp.StatusCode if status == http.StatusOK { - responseBytes, err := ioutil.ReadAll(resp.Body) + responseBytes, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -118,3 +118,4 @@ func (ifsc *IFSCResponse) GetBankName() string { } return bankName } + diff --git a/src/go/client_test.go b/src/go/client_test.go index 9d597921..79305cb5 100644 --- a/src/go/client_test.go +++ b/src/go/client_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "errors" - "io/ioutil" + "io" "net/http" "testing" @@ -157,7 +157,7 @@ func GetSuccessMockResponse() { "BANKCODE":"HDFC", "IFSC":"HDFC0CAGSBK" }` - r := ioutil.NopCloser(bytes.NewReader([]byte(successJson))) + r := io.NopCloser(bytes.NewReader([]byte(successJson))) return &http.Response{ StatusCode: http.StatusOK, Body: r, @@ -217,3 +217,4 @@ func TestIFSCResponse_GetBankName(t *testing.T) { }) } } + diff --git a/src/go/generator/main.go b/src/go/generator/main.go index 3e743865..0cab6b88 100644 --- a/src/go/generator/main.go +++ b/src/go/generator/main.go @@ -1,24 +1,21 @@ package main import ( // nosemgrep go.lang.security.audit.xss.import-text-template.import-text-template + "encoding/json" "fmt" - "text/template" "io" - "io/ioutil" "log" "os" "sort" - "encoding/json" + "text/template" ) - type bankConstants struct { Value []string } - -func GetConstants() (*bankConstants) { - jsonString, _ := ioutil.ReadFile("src/banknames.json") +func GetConstants() *bankConstants { + jsonString, _ := os.ReadFile("src/banknames.json") var result bankConstants var data map[string]interface{} json.Unmarshal([]byte(jsonString), &data) @@ -30,14 +27,14 @@ func GetConstants() (*bankConstants) { sort.Strings(keys) - for _,k := range keys { + for _, k := range keys { result.Value = append(result.Value, k) } return &result } func GenerateConstantsFile(outputFileWriter io.Writer, templateFilePath string, constantsArr *bankConstants) error { - fileBytes, err := ioutil.ReadFile(templateFilePath) + fileBytes, err := os.ReadFile(templateFilePath) if err != nil { return err } @@ -63,3 +60,4 @@ func main() { } fmt.Printf("Updated %v \n", outputFilePath) } + diff --git a/src/go/ifsc.go b/src/go/ifsc.go index 952569aa..998bf268 100644 --- a/src/go/ifsc.go +++ b/src/go/ifsc.go @@ -4,8 +4,8 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "log" + "os" "path" "runtime" "strconv" @@ -77,7 +77,7 @@ func LoadFile(fileName string, result interface{}, fullDirPath string) error { completePath = path.Join(jsonDir, fileName) } - bytes, err := ioutil.ReadFile(completePath) + bytes, err := os.ReadFile(completePath) if err != nil { return err } @@ -165,3 +165,4 @@ func ValidateBankCode(bankCodeInput string) bool { _, ok := bankCodes[bankCodeInput] return ok } + diff --git a/src/go/ifsc_test.go b/src/go/ifsc_test.go index 95858037..02caebe4 100644 --- a/src/go/ifsc_test.go +++ b/src/go/ifsc_test.go @@ -16,7 +16,7 @@ func TestGetBankName_BankName(t *testing.T) { func TestGetBankName_Sublet(t *testing.T) { assert := assert.New(t) fixtureData := getSubletFixture() - for input, _ := range fixtureData { + for input := range fixtureData { ownerBankCode := input[0:4] actual, err := GetBankName(input) assert.Nil(err) @@ -117,3 +117,4 @@ func TestValidate(t *testing.T) { }) } } +