From 464e26bd2be4a9b06fcab4f5279fdecde167c9d0 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Tue, 26 Sep 2023 14:18:16 +0200 Subject: [PATCH] Remove dependency on io/ioutil module This fixes lint errors generated in CI after upgrading go version into 1.19.6. Signed-off-by: Periyasamy Palanisamy --- cache/doc.go | 2 +- cmd/modelgen/main.go | 4 ++-- cmd/print_schema/print_schema.go | 4 ++-- mapper/mapper.go | 10 ++++++---- model/model.go | 13 +++++++------ modelgen/generator.go | 6 +++--- ovsdb/schema.go | 5 ++--- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/cache/doc.go b/cache/doc.go index 3b176f27..25f1597e 100644 --- a/cache/doc.go +++ b/cache/doc.go @@ -3,7 +3,7 @@ Package cache provides a cache of model.Model elements that can be used in an OV The cache can be accessed using a simple API: - cache.Table("Open_vSwitch").Row("") + cache.Table("Open_vSwitch").Row("") It implements the ovsdb.NotificationHandler interface such that it can be populated automatically by diff --git a/cmd/modelgen/main.go b/cmd/modelgen/main.go index 59883379..7c9733e3 100644 --- a/cmd/modelgen/main.go +++ b/cmd/modelgen/main.go @@ -4,7 +4,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -56,7 +56,7 @@ func main() { } defer schemaFile.Close() - schemaBytes, err := ioutil.ReadAll(schemaFile) + schemaBytes, err := io.ReadAll(schemaFile) if err != nil { log.Fatal(err) } diff --git a/cmd/print_schema/print_schema.go b/cmd/print_schema/print_schema.go index e1b5fe06..2cbdd090 100644 --- a/cmd/print_schema/print_schema.go +++ b/cmd/print_schema/print_schema.go @@ -4,7 +4,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "log" "os" "runtime" @@ -53,7 +53,7 @@ func main() { } defer schemaFile.Close() - schemaBytes, err := ioutil.ReadAll(schemaFile) + schemaBytes, err := io.ReadAll(schemaFile) if err != nil { log.Fatal(err) } diff --git a/mapper/mapper.go b/mapper/mapper.go index 5ca7a412..56a0fa2b 100644 --- a/mapper/mapper.go +++ b/mapper/mapper.go @@ -12,12 +12,14 @@ import ( // to what column in the database id through field a field tag. // The tag used is "ovsdb" and has the following structure // 'ovsdb:"${COLUMN_NAME}"' +// // where COLUMN_NAME is the name of the column and must match the schema // -//Example: -// type MyObj struct { -// Name string `ovsdb:"name"` -// } +// Example: +// +// type MyObj struct { +// Name string `ovsdb:"name"` +// } type Mapper struct { Schema ovsdb.DatabaseSchema } diff --git a/model/model.go b/model/model.go index c8575f5b..618e28e7 100644 --- a/model/model.go +++ b/model/model.go @@ -16,12 +16,13 @@ import ( // The struct may also have non-tagged fields (which will be ignored by the API calls) // The Model interface must be implemented by the pointer to such type // Example: -//type MyLogicalRouter struct { -// UUID string `ovsdb:"_uuid"` -// Name string `ovsdb:"name"` -// ExternalIDs map[string]string `ovsdb:"external_ids"` -// LoadBalancers []string `ovsdb:"load_balancer"` -//} +// +// type MyLogicalRouter struct { +// UUID string `ovsdb:"_uuid"` +// Name string `ovsdb:"name"` +// ExternalIDs map[string]string `ovsdb:"external_ids"` +// LoadBalancers []string `ovsdb:"load_balancer"` +// } type Model interface{} type CloneableModel interface { diff --git a/modelgen/generator.go b/modelgen/generator.go index daa5c861..c10d3ce7 100644 --- a/modelgen/generator.go +++ b/modelgen/generator.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" "go/format" - "io/ioutil" "log" + "os" "text/template" ) @@ -47,11 +47,11 @@ func (g *generator) Generate(filename string, tmpl *template.Template, args inte fmt.Print("\n") return nil } - content, err := ioutil.ReadFile(filename) + content, err := os.ReadFile(filename) if err == nil && bytes.Equal(content, src) { return nil } - return ioutil.WriteFile(filename, src, 0644) + return os.WriteFile(filename, src, 0644) } // NewGenerator returns a new Generator diff --git a/ovsdb/schema.go b/ovsdb/schema.go index cf80aa50..dca119e8 100644 --- a/ovsdb/schema.go +++ b/ovsdb/schema.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math" "os" "strings" @@ -48,7 +47,7 @@ func (schema DatabaseSchema) Print(w io.Writer) { // SchemaFromFile returns a DatabaseSchema from a file func SchemaFromFile(f *os.File) (DatabaseSchema, error) { - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { return DatabaseSchema{}, err } @@ -124,7 +123,7 @@ of this library, we define an ExtendedType that includes all possible column typ atomic fields). */ -//ExtendedType includes atomic types as defined in the RFC plus Enum, Map and Set +// ExtendedType includes atomic types as defined in the RFC plus Enum, Map and Set type ExtendedType = string // RefType is used to define the possible RefTypes