From 9e5fc68fd1f8ee9441117855840cec3baba52b48 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Thu, 19 Dec 2024 14:01:55 +0530 Subject: [PATCH 1/7] remofe gofr's dependency from ftp package --- pkg/gofr/datasource/file/ftp/file.go | 8 +-- pkg/gofr/datasource/file/ftp/fs.go | 10 ++- pkg/gofr/datasource/file/ftp/fs_dir.go | 8 +-- pkg/gofr/datasource/file/ftp/go.mod | 7 +- pkg/gofr/datasource/file/ftp/go.sum | 8 --- pkg/gofr/datasource/file/ftp/interface.go | 84 +++++++++++++++++++++++ 6 files changed, 95 insertions(+), 30 deletions(-) diff --git a/pkg/gofr/datasource/file/ftp/file.go b/pkg/gofr/datasource/file/ftp/file.go index fc16129dc..da2557080 100644 --- a/pkg/gofr/datasource/file/ftp/file.go +++ b/pkg/gofr/datasource/file/ftp/file.go @@ -14,8 +14,6 @@ import ( "time" "github.com/jlaffaye/ftp" - - file_interface "gofr.dev/pkg/gofr/datasource/file" ) var ( @@ -50,7 +48,7 @@ type jsonReader struct { } // ReadAll reads either JSON or text files based on file extension and returns a corresponding RowReader. -func (f *File) ReadAll() (file_interface.RowReader, error) { +func (f *File) ReadAll() (RowReader, error) { defer f.sendOperationStats(&FileLog{Operation: "ReadAll", Location: f.path}, time.Now()) if strings.HasSuffix(f.Name(), ".json") { @@ -61,7 +59,7 @@ func (f *File) ReadAll() (file_interface.RowReader, error) { } // createJSONReader creates a JSON reader for JSON files. -func (f *File) createJSONReader() (file_interface.RowReader, error) { +func (f *File) createJSONReader() (RowReader, error) { status := statusError defer f.sendOperationStats(&FileLog{Operation: "JSON Reader", Location: f.path, Status: &status}, time.Now()) @@ -106,7 +104,7 @@ func (f *File) createJSONReader() (file_interface.RowReader, error) { } // createTextCSVReader creates a text reader for reading text files. -func (f *File) createTextCSVReader() (file_interface.RowReader, error) { +func (f *File) createTextCSVReader() (RowReader, error) { status := statusError defer f.sendOperationStats(&FileLog{Operation: "Text/CSV Reader", Location: f.path, Status: &status}, time.Now()) diff --git a/pkg/gofr/datasource/file/ftp/fs.go b/pkg/gofr/datasource/file/ftp/fs.go index 85e5908db..419667e5f 100644 --- a/pkg/gofr/datasource/file/ftp/fs.go +++ b/pkg/gofr/datasource/file/ftp/fs.go @@ -10,8 +10,6 @@ import ( "time" "github.com/jlaffaye/ftp" - - file_interface "gofr.dev/pkg/gofr/datasource/file" ) const ( @@ -60,7 +58,7 @@ type Config struct { } // New initializes a new instance of FTP fileSystem with provided configuration. -func New(config *Config) file_interface.FileSystemProvider { +func New(config *Config) FileSystemProvider { return &FileSystem{config: config} } @@ -125,7 +123,7 @@ func (f *FileSystem) Connect() { } // Create creates an empty file on the FTP server. -func (f *FileSystem) Create(name string) (file_interface.File, error) { +func (f *FileSystem) Create(name string) (FTPFile, error) { filePath := path.Join(f.config.RemoteDir, name) var msg string @@ -188,7 +186,7 @@ func (f *FileSystem) Create(name string) (file_interface.File, error) { // Open retrieves a file from the FTP server and returns a file handle. // Note: Here Open and OpenFile both methods have been implemented so that the // FTP FileSystem comply with the gofr FileSystem interface. -func (f *FileSystem) Open(name string) (file_interface.File, error) { +func (f *FileSystem) Open(name string) (FTPFile, error) { var msg string status := statusError @@ -242,7 +240,7 @@ func (f *FileSystem) Open(name string) (file_interface.File, error) { // Permissions are not clear for Ftp as file commands do not accept an argument and don't store their file permissions. // currently, this function just calls the Open function. // Here, os.FileMode is unused, but is added to comply with FileSystem interface. -func (f *FileSystem) OpenFile(name string, _ int, _ os.FileMode) (file_interface.File, error) { +func (f *FileSystem) OpenFile(name string, _ int, _ os.FileMode) (FTPFile, error) { return f.Open(name) } diff --git a/pkg/gofr/datasource/file/ftp/fs_dir.go b/pkg/gofr/datasource/file/ftp/fs_dir.go index 021647ba4..4f1407f9f 100644 --- a/pkg/gofr/datasource/file/ftp/fs_dir.go +++ b/pkg/gofr/datasource/file/ftp/fs_dir.go @@ -8,8 +8,6 @@ import ( "time" "github.com/jlaffaye/ftp" - - file_interface "gofr.dev/pkg/gofr/datasource/file" ) // Mkdir creates a directory on the FTP server. @@ -156,7 +154,7 @@ func (f *FileSystem) RemoveAll(name string) error { } // Stat returns information of the files/directories in the specified directory. -func (f *FileSystem) Stat(name string) (file_interface.FileInfo, error) { +func (f *FileSystem) Stat(name string) (FileInfo, error) { status := statusError defer f.sendOperationStats(&FileLog{ @@ -248,7 +246,7 @@ func (f *FileSystem) ChDir(dir string) error { // ReadDir reads the named directory, returning all its directory entries sorted by filename. // If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error. // It returns the list of files/directories present in the current directory when "." is passed. -func (f *FileSystem) ReadDir(dir string) ([]file_interface.FileInfo, error) { +func (f *FileSystem) ReadDir(dir string) ([]FileInfo, error) { var msg string status := statusError @@ -271,7 +269,7 @@ func (f *FileSystem) ReadDir(dir string) ([]file_interface.FileInfo, error) { return nil, err } - fileInfo := make([]file_interface.FileInfo, 0) + fileInfo := make([]FileInfo, 0) for _, entry := range entries { entryPath := path.Join(filepath, entry.Name) diff --git a/pkg/gofr/datasource/file/ftp/go.mod b/pkg/gofr/datasource/file/ftp/go.mod index d7ec22559..40526b2f0 100644 --- a/pkg/gofr/datasource/file/ftp/go.mod +++ b/pkg/gofr/datasource/file/ftp/go.mod @@ -1,23 +1,18 @@ module gofr.dev/pkg/gofr/datasource/file/ftp -go 1.22.3 - -replace gofr.dev => ../../../../../../gofr +go 1.22.7 require ( github.com/jlaffaye/ftp v0.2.0 github.com/stretchr/testify v1.10.0 go.uber.org/mock v0.5.0 - gofr.dev v1.15.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/pkg/gofr/datasource/file/ftp/go.sum b/pkg/gofr/datasource/file/ftp/go.sum index 04153f28d..e90b9d5a3 100644 --- a/pkg/gofr/datasource/file/ftp/go.sum +++ b/pkg/gofr/datasource/file/ftp/go.sum @@ -7,8 +7,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/jlaffaye/ftp v0.2.0 h1:lXNvW7cBu7R/68bknOX3MrRIIqZ61zELs1P2RAiA3lg= github.com/jlaffaye/ftp v0.2.0/go.mod h1:is2Ds5qkhceAPy2xD6RLI6hmp/qysSoymZ+Z2uTnspI= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -17,8 +15,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -28,10 +24,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= -golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/pkg/gofr/datasource/file/ftp/interface.go b/pkg/gofr/datasource/file/ftp/interface.go index 0b24261fe..14c212096 100644 --- a/pkg/gofr/datasource/file/ftp/interface.go +++ b/pkg/gofr/datasource/file/ftp/interface.go @@ -3,11 +3,82 @@ package ftp import ( "context" "io" + "os" "time" "github.com/jlaffaye/ftp" ) +// FTPFile represents a file in the filesystem. +type FTPFile interface { + io.Closer + io.Reader + io.ReaderAt + io.Seeker + io.Writer + io.WriterAt + + ReadAll() (RowReader, error) +} + +type FileInfo interface { + Name() string // base name of the file + Size() int64 // length in bytes for regular files; system-dependent for others + ModTime() time.Time // modification time + Mode() os.FileMode // file mode bits + IsDir() bool // abbreviation for Mode().IsDir() +} + +type RowReader interface { + Next() bool + Scan(interface{}) error +} + +// FTPFileSystem : Any simulated or real filesystem should implement this interface. +type FTPFileSystem interface { + // Create creates a file in the filesystem, returning the file and an + // error, if any happens. + Create(name string) (FTPFile, error) + + // TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations + // Mkdir creates a directory in the filesystem, return an error if any + // happens. + Mkdir(name string, perm os.FileMode) error + + // MkdirAll creates a directory path and all parents that does not exist + // yet. + MkdirAll(path string, perm os.FileMode) error + + // Open opens a file, returning it or an error, if any happens. + Open(name string) (FTPFile, error) + + // OpenFile opens a file using the given flags and the given mode. + OpenFile(name string, flag int, perm os.FileMode) (FTPFile, error) + + // Remove removes a file identified by name, returning an error, if any + // happens. + Remove(name string) error + + // RemoveAll removes a directory path and any children it contains. It + // does not fail if the path does not exist (return nil). + RemoveAll(path string) error + + // Rename renames a file. + Rename(oldname, newname string) error + + // ReadDir returns a list of files/directories present in the directory. + ReadDir(dir string) ([]FileInfo, error) + + // Stat returns the file/directory information in the directory. + Stat(name string) (FileInfo, error) + + // ChDir changes the current directory. + ChDir(dirname string) error + + // Getwd returns the path of the current directory. + Getwd() (string, error) +} + // Logger interface is used by ftp package to log information about query execution. type Logger interface { Debug(args ...interface{}) @@ -47,3 +118,16 @@ type ftpResponse interface { Close() error SetDeadline(t time.Time) error } + +type FileSystemProvider interface { + FTPFileSystem + + // UseLogger sets the logger for the FileSystem client. + UseLogger(logger interface{}) + + // UseMetrics sets the metrics for the FileSystem client. + UseMetrics(metrics interface{}) + + // Connect establishes a connection to FileSystem and registers metrics using the provided configuration when the client was Created. + Connect() +} From 7cd57256d43dd63bf06cd030cecb27dd8e9136c4 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Thu, 19 Dec 2024 17:23:47 +0530 Subject: [PATCH 2/7] make file system interface generic and add wrapper to return file.File instead of interface --- pkg/gofr/datasource/interface.go | 33 ++++++++++++--------- pkg/gofr/external_db.go | 11 ++++--- pkg/gofr/file_handler.go | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 pkg/gofr/file_handler.go diff --git a/pkg/gofr/datasource/interface.go b/pkg/gofr/datasource/interface.go index c2aa97637..5bc5e18ef 100644 --- a/pkg/gofr/datasource/interface.go +++ b/pkg/gofr/datasource/interface.go @@ -1,8 +1,8 @@ package datasource import ( - "errors" "io" + "io/fs" "os" ) @@ -15,7 +15,7 @@ type File interface { io.Writer io.WriterAt - ReadAll() (RowReader, error) + ReadAll() (any, error) } type RowReader interface { @@ -27,7 +27,9 @@ type RowReader interface { type FileSystem interface { // Create creates a file in the filesystem, returning the file and an // error, if any happens. - Create(name string) (File, error) + Create(name string) (any, error) + + //TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations // Mkdir creates a directory in the filesystem, return an error if any // happens. @@ -38,10 +40,10 @@ type FileSystem interface { MkdirAll(path string, perm os.FileMode) error // Open opens a file, returning it or an error, if any happens. - Open(name string) (File, error) + Open(name string) (any, error) // OpenFile opens a file using the given flags and the given mode. - OpenFile(name string, flag int, perm os.FileMode) (File, error) + OpenFile(name string, flag int, perm os.FileMode) (any, error) // Remove removes a file identified by name, returning an error, if any // happens. @@ -53,16 +55,19 @@ type FileSystem interface { // Rename renames a file. Rename(oldname, newname string) error -} -var ( - ErrFileClosed = errors.New("File is closed") - ErrOutOfRange = errors.New("out of range") - ErrTooLarge = errors.New("too large") - ErrFileNotFound = os.ErrNotExist - ErrFileExists = os.ErrExist - ErrDestinationExists = os.ErrExist -) + // ReadDir returns a list of files/directories present in the directory. + ReadDir(dir string) ([]fs.FileInfo, error) + + // Stat returns the file/directory information in the directory. + Stat(name string) (fs.FileInfo, error) + + // ChDir changes the current directory. + ChDir(dirname string) error + + // Getwd returns the path of the current directory. + Getwd() (string, error) +} type FileSystemProvider interface { FileSystem diff --git a/pkg/gofr/external_db.go b/pkg/gofr/external_db.go index 4d56fb086..05625271e 100644 --- a/pkg/gofr/external_db.go +++ b/pkg/gofr/external_db.go @@ -2,9 +2,8 @@ package gofr import ( "go.opentelemetry.io/otel" - "gofr.dev/pkg/gofr/container" - "gofr.dev/pkg/gofr/datasource/file" + "gofr.dev/pkg/gofr/datasource" ) // AddMongo sets the Mongo datasource in the app's container. @@ -23,13 +22,13 @@ func (a *App) AddMongo(db container.MongoProvider) { // AddFTP sets the FTP datasource in the app's container. // Deprecated: Use the AddFile method instead. -func (a *App) AddFTP(fs file.FileSystemProvider) { +func (a *App) AddFTP(fs datasource.FileSystemProvider) { fs.UseLogger(a.Logger()) fs.UseMetrics(a.Metrics()) fs.Connect() - a.container.File = fs + a.container.File = &fileSysWrapper{fs} } // AddPubSub sets the PubSub client in the app's container. @@ -43,13 +42,13 @@ func (a *App) AddPubSub(pubsub container.PubSubProvider) { } // AddFile sets the FTP,SFTP,S3 datasource in the app's container. -func (a *App) AddFileStore(fs file.FileSystemProvider) { +func (a *App) AddFileStore(fs datasource.FileSystemProvider) { fs.UseLogger(a.Logger()) fs.UseMetrics(a.Metrics()) fs.Connect() - a.container.File = fs + a.container.File = &fileSysWrapper{fs} } // AddClickhouse initializes the clickhouse client. diff --git a/pkg/gofr/file_handler.go b/pkg/gofr/file_handler.go new file mode 100644 index 000000000..737509994 --- /dev/null +++ b/pkg/gofr/file_handler.go @@ -0,0 +1,49 @@ +package gofr + +import ( + "errors" + "os" + + "gofr.dev/pkg/gofr/datasource" + "gofr.dev/pkg/gofr/datasource/file" +) + +// Developer Note: fileSysWrapper wraps a datasource.FileSystem to return file.File instead of an interface, +// this is useful when we want to use the file.File methods, but don't want the external datasource +// to be dependent on any particular version of gofr so that they can be maintained independently. +type fileSysWrapper struct { + datasource.FileSystem +} + +func (fsW *fileSysWrapper) Create(name string) (file.File, error) { + fI, err := fsW.FileSystem.Create(name) + + f, ok := fI.(file.File) + if !ok { + return nil, errors.New("failed to create file") + } + + return f, err +} + +func (fsW *fileSysWrapper) Open(name string) (file.File, error) { + fI, err := fsW.FileSystem.Open(name) + + f, ok := fI.(file.File) + if !ok { + return nil, errors.New("failed to open file") + } + + return f, err +} + +func (fsW *fileSysWrapper) OpenFile(name string, flag int, perm os.FileMode) (file.File, error) { + fI, err := fsW.FileSystem.OpenFile(name, flag, perm) + + f, ok := fI.(file.File) + if !ok { + return nil, errors.New("failed to open file") + } + + return f, err +} From dc4e45df920bc719d9044e26747ec8ffb6cbb4fd Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Thu, 19 Dec 2024 17:30:04 +0530 Subject: [PATCH 3/7] use io/fs lib to make local file system generic --- pkg/gofr/datasource/file/file.go | 3 ++ pkg/gofr/datasource/file/fs.go | 48 +++++++++++++++++---------- pkg/gofr/datasource/file/fs_test.go | 19 ++++++----- pkg/gofr/datasource/file/interface.go | 38 +++------------------ 4 files changed, 48 insertions(+), 60 deletions(-) diff --git a/pkg/gofr/datasource/file/file.go b/pkg/gofr/datasource/file/file.go index d124f2c94..45fd48bf9 100644 --- a/pkg/gofr/datasource/file/file.go +++ b/pkg/gofr/datasource/file/file.go @@ -1,3 +1,6 @@ +// Package file provides the implementation of the file system operations on local system. +// It provides the functionality to create, open, read and write the file and other file and directory operations. +// this package provides the functionality to read the file in JSON, CSV or text format package file import ( diff --git a/pkg/gofr/datasource/file/fs.go b/pkg/gofr/datasource/file/fs.go index 056a0b430..55c8075db 100644 --- a/pkg/gofr/datasource/file/fs.go +++ b/pkg/gofr/datasource/file/fs.go @@ -1,22 +1,27 @@ package file import ( + "io/fs" "os" "path" "gofr.dev/pkg/gofr/datasource" ) -type fileSystem struct { +type FileSys struct { logger datasource.Logger } -// New initializes local filesystem with logger. -func New(logger datasource.Logger) FileSystem { - return fileSystem{logger: logger} +// New initializes local filesystem with logger and provides the functionality to interact with the files and directories on local system. +func New(logger datasource.Logger) *FileSys { + return &FileSys{logger: logger} } -func (f fileSystem) Create(name string) (File, error) { +// Create creates or truncates the named file. If the file already exists, it is truncated. +// If the file does not exist, it is created with mode 666. +// If successful, methods on the returned File can be used for I/ O; the associated file descriptor has mode O_RDWR. +// If there is an error, it will be of type *PathError +func (f *FileSys) Create(name string) (File, error) { newFile, err := os.Create(name) if err != nil { return nil, err @@ -25,15 +30,19 @@ func (f fileSystem) Create(name string) (File, error) { return &file{File: newFile, logger: f.logger}, nil } -func (fileSystem) Mkdir(name string, perm os.FileMode) error { +// Mkdir creates a new directory with the specified name and permission bits (before umask). +func (*FileSys) Mkdir(name string, perm os.FileMode) error { return os.Mkdir(name, perm) } -func (fileSystem) MkdirAll(name string, perm os.FileMode) error { +// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. +func (*FileSys) MkdirAll(name string, perm os.FileMode) error { return os.MkdirAll(name, perm) } -func (f fileSystem) Open(name string) (File, error) { +// Open opens the named file for reading. +// If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. +func (f *FileSys) Open(name string) (File, error) { openFile, err := os.Open(name) if err != nil { return nil, err @@ -42,7 +51,9 @@ func (f fileSystem) Open(name string) (File, error) { return &file{File: openFile, logger: f.logger}, nil } -func (f fileSystem) OpenFile(name string, flag int, perm os.FileMode) (File, error) { +// OpenFile is the generalized open call; most users will use Open or Create instead. +// It takes flag and perm attributes to open the file. +func (f *FileSys) OpenFile(name string, flag int, perm os.FileMode) (File, error) { openFile, err := os.OpenFile(name, flag, perm) if err != nil { return nil, err @@ -51,11 +62,13 @@ func (f fileSystem) OpenFile(name string, flag int, perm os.FileMode) (File, err return &file{File: openFile, logger: f.logger}, nil } -func (fileSystem) Remove(name string) error { +// Remove removes the named file or (empty) directory. +func (*FileSys) Remove(name string) error { return os.Remove(name) } -func (fileSystem) RemoveAll(name string) error { +// RemoveAll removes path and any children it contains. +func (*FileSys) RemoveAll(name string) error { // In case we remove current working directory, say using "../currentDir" // the current directory needs to be reset to its parent directory. curr, err := os.Getwd() @@ -79,33 +92,34 @@ func (fileSystem) RemoveAll(name string) error { return nil } -func (fileSystem) Rename(oldname, newname string) error { +// Rename renames (moves) old path to new path. +func (*FileSys) Rename(oldname, newname string) error { return os.Rename(oldname, newname) } // Stat returns the file/directory info. -func (fileSystem) Stat(name string) (FileInfo, error) { +func (*FileSys) Stat(name string) (fs.FileInfo, error) { return os.Stat(name) } // Getwd returns the full path of the current working directory. -func (fileSystem) Getwd() (string, error) { +func (*FileSys) Getwd() (string, error) { return os.Getwd() } // ChDir changes the current working directory to the named directory. // If there is an error, it will be of type *PathError. -func (fileSystem) ChDir(dir string) error { +func (*FileSys) ChDir(dir string) error { return os.Chdir(dir) } // ReadDir reads the named directory, returning all its directory entries sorted by filename. // If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error. // It returns the list of files/directories present in the current directory when "." is passed. -func (fileSystem) ReadDir(dir string) ([]FileInfo, error) { +func (*FileSys) ReadDir(dir string) ([]fs.FileInfo, error) { entries, err := os.ReadDir(dir) - fileInfo := make([]FileInfo, len(entries)) + fileInfo := make([]fs.FileInfo, len(entries)) for i := range entries { fileInfo[i], err = entries[i].Info() if err != nil { diff --git a/pkg/gofr/datasource/file/fs_test.go b/pkg/gofr/datasource/file/fs_test.go index 7322647f9..33cb72646 100644 --- a/pkg/gofr/datasource/file/fs_test.go +++ b/pkg/gofr/datasource/file/fs_test.go @@ -62,11 +62,12 @@ func Test_CreateReadDeleteFile(t *testing.T) { fileStore := New(logger) - newFile, err := fileStore.Create(fileName) + fi, err := fileStore.Create(fileName) + newFile := fi.(*file) _, _ = newFile.Write([]byte("some content")) - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.Remove(name) }(fileStore, fileName) @@ -94,7 +95,7 @@ func Test_CreateMoveDeleteFile(t *testing.T) { require.NoError(t, err) err = fileStore.Rename("temp.txt", "temp.text") - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.Remove(name) }(fileStore, "temp.text") @@ -112,7 +113,7 @@ func Test_CreateUpdateReadFile(t *testing.T) { _, _ = newFile.Write([]byte("some content")) - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.Remove(name) }(fileStore, fileName) @@ -178,7 +179,7 @@ Michael Brown,40,michaelb@example.com` newCsvFile, _ = fileStore.Open("temp.csv") reader, _ := newCsvFile.ReadAll() - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.RemoveAll(name) }(fileStore, "temp.csv") @@ -211,7 +212,7 @@ func Test_ReadFromCSVScanError(t *testing.T) { newCsvFile, _ = fileStore.Open("temp.csv") reader, _ := newCsvFile.ReadAll() - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.RemoveAll(name) }(fileStore, "temp.csv") @@ -246,7 +247,7 @@ func Test_ReadFromJSONArray(t *testing.T) { newCsvFile, _ = fileStore.Open("temp.json") reader, _ := newCsvFile.ReadAll() - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.RemoveAll(name) }(fileStore, "temp.json") @@ -285,7 +286,7 @@ func Test_ReadFromJSONObject(t *testing.T) { newCsvFile, _ = fileStore.Open("temp.json") reader, _ := newCsvFile.ReadAll() - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.RemoveAll(name) }(fileStore, "temp.json") @@ -316,7 +317,7 @@ func Test_ReadFromJSONArrayInvalidDelimiter(t *testing.T) { _, err := newCsvFile.ReadAll() - defer func(fileStore FileSystem, name string) { + defer func(fileStore *FileSys, name string) { _ = fileStore.RemoveAll(name) }(fileStore, "temp.json") diff --git a/pkg/gofr/datasource/file/interface.go b/pkg/gofr/datasource/file/interface.go index fe6622663..de756faee 100644 --- a/pkg/gofr/datasource/file/interface.go +++ b/pkg/gofr/datasource/file/interface.go @@ -1,10 +1,9 @@ package file import ( - "errors" "io" + "io/fs" "os" - "time" ) // File represents a file in the filesystem. @@ -19,14 +18,6 @@ type File interface { ReadAll() (RowReader, error) } -type FileInfo interface { - Name() string // base name of the file - Size() int64 // length in bytes for regular files; system-dependent for others - ModTime() time.Time // modification time - Mode() os.FileMode // file mode bits - IsDir() bool // abbreviation for Mode().IsDir() -} - type RowReader interface { Next() bool Scan(interface{}) error @@ -39,6 +30,7 @@ type FileSystem interface { Create(name string) (File, error) // TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations + // Mkdir creates a directory in the filesystem, return an error if any // happens. Mkdir(name string, perm os.FileMode) error @@ -65,10 +57,10 @@ type FileSystem interface { Rename(oldname, newname string) error // ReadDir returns a list of files/directories present in the directory. - ReadDir(dir string) ([]FileInfo, error) + ReadDir(dir string) ([]fs.FileInfo, error) // Stat returns the file/directory information in the directory. - Stat(name string) (FileInfo, error) + Stat(name string) (fs.FileInfo, error) // ChDir changes the current directory. ChDir(dirname string) error @@ -76,25 +68,3 @@ type FileSystem interface { // Getwd returns the path of the current directory. Getwd() (string, error) } - -var ( - ErrFileClosed = errors.New("File is closed") - ErrOutOfRange = errors.New("out of range") - ErrTooLarge = errors.New("too large") - ErrFileNotFound = os.ErrNotExist - ErrFileExists = os.ErrExist - ErrDestinationExists = os.ErrExist -) - -type FileSystemProvider interface { - FileSystem - - // UseLogger sets the logger for the FileSystem client. - UseLogger(logger interface{}) - - // UseMetrics sets the metrics for the FileSystem client. - UseMetrics(metrics interface{}) - - // Connect establishes a connection to FileSystem and registers metrics using the provided configuration when the client was Created. - Connect() -} From 9bf83ab7e4ff584b9ac3bb2afe468e15a8b60e52 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Thu, 19 Dec 2024 17:40:24 +0530 Subject: [PATCH 4/7] make changes in method signatures of ftp to match with interface --- pkg/gofr/datasource/file/ftp/file.go | 12 +++- pkg/gofr/datasource/file/ftp/fs.go | 11 +-- pkg/gofr/datasource/file/ftp/fs_dir.go | 7 +- pkg/gofr/datasource/file/ftp/interface.go | 84 ----------------------- 4 files changed, 20 insertions(+), 94 deletions(-) diff --git a/pkg/gofr/datasource/file/ftp/file.go b/pkg/gofr/datasource/file/ftp/file.go index da2557080..6259c7648 100644 --- a/pkg/gofr/datasource/file/ftp/file.go +++ b/pkg/gofr/datasource/file/ftp/file.go @@ -19,6 +19,8 @@ import ( var ( // errNotPointer is returned when Read method is called with a non-pointer argument. errNotPointer = errors.New("input should be a pointer to a string") + + // ErrOutOfRange is returned when the offset is out of range. ErrOutOfRange = errors.New("out of range") ) @@ -47,8 +49,12 @@ type jsonReader struct { token json.Token } +func (f *File) Sys() any { + return "ftp" +} + // ReadAll reads either JSON or text files based on file extension and returns a corresponding RowReader. -func (f *File) ReadAll() (RowReader, error) { +func (f *File) ReadAll() (any, error) { defer f.sendOperationStats(&FileLog{Operation: "ReadAll", Location: f.path}, time.Now()) if strings.HasSuffix(f.Name(), ".json") { @@ -59,7 +65,7 @@ func (f *File) ReadAll() (RowReader, error) { } // createJSONReader creates a JSON reader for JSON files. -func (f *File) createJSONReader() (RowReader, error) { +func (f *File) createJSONReader() (any, error) { status := statusError defer f.sendOperationStats(&FileLog{Operation: "JSON Reader", Location: f.path, Status: &status}, time.Now()) @@ -104,7 +110,7 @@ func (f *File) createJSONReader() (RowReader, error) { } // createTextCSVReader creates a text reader for reading text files. -func (f *File) createTextCSVReader() (RowReader, error) { +func (f *File) createTextCSVReader() (any, error) { status := statusError defer f.sendOperationStats(&FileLog{Operation: "Text/CSV Reader", Location: f.path, Status: &status}, time.Now()) diff --git a/pkg/gofr/datasource/file/ftp/fs.go b/pkg/gofr/datasource/file/ftp/fs.go index 419667e5f..23c1928ce 100644 --- a/pkg/gofr/datasource/file/ftp/fs.go +++ b/pkg/gofr/datasource/file/ftp/fs.go @@ -28,6 +28,9 @@ func (c *Conn) Retr(filepath string) (ftpResponse, error) { return c.ServerConn.Retr(filepath) } +// RetrFrom wraps the Retrieve method for FTP server to return a ftpResponse interface type. +// The RetrFrom issues a RETR FTP command to fetch the specified file from the remote FTP server, +// the server will not send the offset first bytes of the file. func (c *Conn) RetrFrom(filepath string, offset uint64) (ftpResponse, error) { return c.ServerConn.RetrFrom(filepath, offset) } @@ -58,7 +61,7 @@ type Config struct { } // New initializes a new instance of FTP fileSystem with provided configuration. -func New(config *Config) FileSystemProvider { +func New(config *Config) *FileSystem { return &FileSystem{config: config} } @@ -123,7 +126,7 @@ func (f *FileSystem) Connect() { } // Create creates an empty file on the FTP server. -func (f *FileSystem) Create(name string) (FTPFile, error) { +func (f *FileSystem) Create(name string) (any, error) { filePath := path.Join(f.config.RemoteDir, name) var msg string @@ -186,7 +189,7 @@ func (f *FileSystem) Create(name string) (FTPFile, error) { // Open retrieves a file from the FTP server and returns a file handle. // Note: Here Open and OpenFile both methods have been implemented so that the // FTP FileSystem comply with the gofr FileSystem interface. -func (f *FileSystem) Open(name string) (FTPFile, error) { +func (f *FileSystem) Open(name string) (any, error) { var msg string status := statusError @@ -240,7 +243,7 @@ func (f *FileSystem) Open(name string) (FTPFile, error) { // Permissions are not clear for Ftp as file commands do not accept an argument and don't store their file permissions. // currently, this function just calls the Open function. // Here, os.FileMode is unused, but is added to comply with FileSystem interface. -func (f *FileSystem) OpenFile(name string, _ int, _ os.FileMode) (FTPFile, error) { +func (f *FileSystem) OpenFile(name string, _ int, _ os.FileMode) (any, error) { return f.Open(name) } diff --git a/pkg/gofr/datasource/file/ftp/fs_dir.go b/pkg/gofr/datasource/file/ftp/fs_dir.go index 4f1407f9f..284b5896f 100644 --- a/pkg/gofr/datasource/file/ftp/fs_dir.go +++ b/pkg/gofr/datasource/file/ftp/fs_dir.go @@ -2,6 +2,7 @@ package ftp import ( "fmt" + "io/fs" "os" "path" "slices" @@ -154,7 +155,7 @@ func (f *FileSystem) RemoveAll(name string) error { } // Stat returns information of the files/directories in the specified directory. -func (f *FileSystem) Stat(name string) (FileInfo, error) { +func (f *FileSystem) Stat(name string) (fs.FileInfo, error) { status := statusError defer f.sendOperationStats(&FileLog{ @@ -246,7 +247,7 @@ func (f *FileSystem) ChDir(dir string) error { // ReadDir reads the named directory, returning all its directory entries sorted by filename. // If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error. // It returns the list of files/directories present in the current directory when "." is passed. -func (f *FileSystem) ReadDir(dir string) ([]FileInfo, error) { +func (f *FileSystem) ReadDir(dir string) ([]fs.FileInfo, error) { var msg string status := statusError @@ -269,7 +270,7 @@ func (f *FileSystem) ReadDir(dir string) ([]FileInfo, error) { return nil, err } - fileInfo := make([]FileInfo, 0) + fileInfo := make([]fs.FileInfo, 0) for _, entry := range entries { entryPath := path.Join(filepath, entry.Name) diff --git a/pkg/gofr/datasource/file/ftp/interface.go b/pkg/gofr/datasource/file/ftp/interface.go index 14c212096..0b24261fe 100644 --- a/pkg/gofr/datasource/file/ftp/interface.go +++ b/pkg/gofr/datasource/file/ftp/interface.go @@ -3,82 +3,11 @@ package ftp import ( "context" "io" - "os" "time" "github.com/jlaffaye/ftp" ) -// FTPFile represents a file in the filesystem. -type FTPFile interface { - io.Closer - io.Reader - io.ReaderAt - io.Seeker - io.Writer - io.WriterAt - - ReadAll() (RowReader, error) -} - -type FileInfo interface { - Name() string // base name of the file - Size() int64 // length in bytes for regular files; system-dependent for others - ModTime() time.Time // modification time - Mode() os.FileMode // file mode bits - IsDir() bool // abbreviation for Mode().IsDir() -} - -type RowReader interface { - Next() bool - Scan(interface{}) error -} - -// FTPFileSystem : Any simulated or real filesystem should implement this interface. -type FTPFileSystem interface { - // Create creates a file in the filesystem, returning the file and an - // error, if any happens. - Create(name string) (FTPFile, error) - - // TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations - // Mkdir creates a directory in the filesystem, return an error if any - // happens. - Mkdir(name string, perm os.FileMode) error - - // MkdirAll creates a directory path and all parents that does not exist - // yet. - MkdirAll(path string, perm os.FileMode) error - - // Open opens a file, returning it or an error, if any happens. - Open(name string) (FTPFile, error) - - // OpenFile opens a file using the given flags and the given mode. - OpenFile(name string, flag int, perm os.FileMode) (FTPFile, error) - - // Remove removes a file identified by name, returning an error, if any - // happens. - Remove(name string) error - - // RemoveAll removes a directory path and any children it contains. It - // does not fail if the path does not exist (return nil). - RemoveAll(path string) error - - // Rename renames a file. - Rename(oldname, newname string) error - - // ReadDir returns a list of files/directories present in the directory. - ReadDir(dir string) ([]FileInfo, error) - - // Stat returns the file/directory information in the directory. - Stat(name string) (FileInfo, error) - - // ChDir changes the current directory. - ChDir(dirname string) error - - // Getwd returns the path of the current directory. - Getwd() (string, error) -} - // Logger interface is used by ftp package to log information about query execution. type Logger interface { Debug(args ...interface{}) @@ -118,16 +47,3 @@ type ftpResponse interface { Close() error SetDeadline(t time.Time) error } - -type FileSystemProvider interface { - FTPFileSystem - - // UseLogger sets the logger for the FileSystem client. - UseLogger(logger interface{}) - - // UseMetrics sets the metrics for the FileSystem client. - UseMetrics(metrics interface{}) - - // Connect establishes a connection to FileSystem and registers metrics using the provided configuration when the client was Created. - Connect() -} From 6dbeeaea94d66df15b916f204f1feed2409763a4 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Fri, 20 Dec 2024 10:49:41 +0530 Subject: [PATCH 5/7] refactor example of using-add-filestore --- examples/using-add-filestore/go.mod | 51 ++++++++------- examples/using-add-filestore/go.sum | 94 ++++++++++++++-------------- examples/using-add-filestore/main.go | 9 +-- pkg/gofr/external_db.go | 2 +- 4 files changed, 80 insertions(+), 76 deletions(-) diff --git a/examples/using-add-filestore/go.mod b/examples/using-add-filestore/go.mod index 85be20be7..0014573e6 100644 --- a/examples/using-add-filestore/go.mod +++ b/examples/using-add-filestore/go.mod @@ -2,6 +2,11 @@ module gofr.dev/examples/using-add-filestore go 1.23.2 +replace ( + gofr.dev v1.28.0 => ../../ + gofr.dev/pkg/gofr/datasource/file/ftp => ../../pkg/gofr/datasource/file/ftp +) + require ( github.com/stretchr/testify v1.10.0 go.uber.org/mock v0.5.0 @@ -11,11 +16,11 @@ require ( require ( cloud.google.com/go v0.116.0 // indirect - cloud.google.com/go/auth v0.10.2 // indirect - cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect - cloud.google.com/go/compute/metadata v0.5.2 // indirect + cloud.google.com/go/auth v0.13.0 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect + cloud.google.com/go/compute/metadata v0.6.0 // indirect cloud.google.com/go/iam v1.2.2 // indirect - cloud.google.com/go/pubsub v1.45.1 // indirect + cloud.google.com/go/pubsub v1.45.3 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect github.com/XSAM/otelsql v0.34.0 // indirect @@ -32,7 +37,6 @@ require ( github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect @@ -40,7 +44,7 @@ require ( github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect @@ -65,39 +69,40 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/segmentio/kafka-go v0.4.47 // indirect go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect - go.opentelemetry.io/otel v1.32.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect + go.opentelemetry.io/otel v1.33.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.52.0 // indirect - go.opentelemetry.io/otel/exporters/zipkin v1.32.0 // indirect - go.opentelemetry.io/otel/metric v1.32.0 // indirect - go.opentelemetry.io/otel/sdk v1.32.0 // indirect + go.opentelemetry.io/otel/exporters/zipkin v1.33.0 // indirect + go.opentelemetry.io/otel/metric v1.33.0 // indirect + go.opentelemetry.io/otel/sdk v1.33.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect - go.opentelemetry.io/otel/trace v1.32.0 // indirect - go.opentelemetry.io/proto/otlp v1.3.1 // indirect + go.opentelemetry.io/otel/trace v1.33.0 // indirect + go.opentelemetry.io/proto/otlp v1.4.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/net v0.31.0 // indirect + golang.org/x/net v0.32.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.27.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.8.0 // indirect - google.golang.org/api v0.209.0 // indirect - google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect - google.golang.org/grpc v1.67.1 // indirect - google.golang.org/protobuf v1.35.2 // indirect + google.golang.org/api v0.212.0 // indirect + google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect + google.golang.org/grpc v1.68.1 // indirect + google.golang.org/protobuf v1.36.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect modernc.org/libc v1.55.3 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.8.0 // indirect - modernc.org/sqlite v1.34.1 // indirect + modernc.org/sqlite v1.34.2 // indirect modernc.org/strutil v1.2.0 // indirect modernc.org/token v1.1.0 // indirect ) diff --git a/examples/using-add-filestore/go.sum b/examples/using-add-filestore/go.sum index ab60fe683..1e24e4ff3 100644 --- a/examples/using-add-filestore/go.sum +++ b/examples/using-add-filestore/go.sum @@ -1,20 +1,20 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE= cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U= -cloud.google.com/go/auth v0.10.2 h1:oKF7rgBfSHdp/kuhXtqU/tNDr0mZqhYbEh+6SiqzkKo= -cloud.google.com/go/auth v0.10.2/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI= -cloud.google.com/go/auth/oauth2adapt v0.2.5 h1:2p29+dePqsCHPP1bqDJcKj4qxRyYCcbzKpFyKGt3MTk= -cloud.google.com/go/auth/oauth2adapt v0.2.5/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8= -cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= -cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= +cloud.google.com/go/auth v0.13.0 h1:8Fu8TZy167JkW8Tj3q7dIkr2v4cndv41ouecJx0PAHs= +cloud.google.com/go/auth v0.13.0/go.mod h1:COOjD9gwfKNKz+IIduatIhYJQIc0mG3H102r/EMxX6Q= +cloud.google.com/go/auth/oauth2adapt v0.2.6 h1:V6a6XDu2lTwPZWOawrAa9HUK+DB2zfJyTuciBG5hFkU= +cloud.google.com/go/auth/oauth2adapt v0.2.6/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8= +cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I= +cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg= cloud.google.com/go/iam v1.2.2 h1:ozUSofHUGf/F4tCNy/mu9tHLTaxZFLOUiKzjcgWHGIA= cloud.google.com/go/iam v1.2.2/go.mod h1:0Ys8ccaZHdI1dEUilwzqng/6ps2YB6vRsjIe00/+6JY= cloud.google.com/go/kms v1.20.1 h1:og29Wv59uf2FVaZlesaiDAqHFzHaoUyHI3HYp9VUHVg= cloud.google.com/go/kms v1.20.1/go.mod h1:LywpNiVCvzYNJWS9JUcGJSVTNSwPwi0vBAotzDqn2nc= cloud.google.com/go/longrunning v0.6.2 h1:xjDfh1pQcWPEvnfjZmwjKQEcHnpz6lHjfy7Fo0MK+hc= cloud.google.com/go/longrunning v0.6.2/go.mod h1:k/vIs83RN4bE3YCswdXC5PFfWVILjm3hpEUlSko4PiI= -cloud.google.com/go/pubsub v1.45.1 h1:ZC/UzYcrmK12THWn1P72z+Pnp2vu/zCZRXyhAfP1hJY= -cloud.google.com/go/pubsub v1.45.1/go.mod h1:3bn7fTmzZFwaUjllitv1WlsNMkqBgGUb3UdMhI54eCc= +cloud.google.com/go/pubsub v1.45.3 h1:prYj8EEAAAwkp6WNoGTE4ahe0DgHoyJd5Pbop931zow= +cloud.google.com/go/pubsub v1.45.3/go.mod h1:cGyloK/hXC4at7smAtxFnXprKEFTqmMXNNd9w+bd94Q= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -111,8 +111,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 h1:TmHmbvxPmaegwhDubVz0lICL0J5Ka2vwTzhoePEXsGE= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0/go.mod h1:qztMSjm835F2bXf+5HKAPIS5qsmQDqZna/PgVt4rWtI= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -211,32 +211,34 @@ go.einride.tech/aip v0.68.0 h1:4seM66oLzTpz50u4K1zlJyOXQ3tCzcJN7I22tKkjipw= go.einride.tech/aip v0.68.0/go.mod h1:7y9FF8VtPWqpxuAxl0KQWqaULxW4zFIesD6zF5RIHHg= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 h1:r6I7RJCN86bpD/FQwedZ0vSixDpwuWREjW9oRMsmqDc= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 h1:4BZHA+B1wXEQoGNHxW8mURaLhcdGwvRnmhGbm+odRbc= go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0/go.mod h1:3qi2EEwMgB4xnKgPLqsDP3j9qxnHDZeHsnAxfjQqTko= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0/go.mod h1:wZcGmeVO9nzP67aYSLDqXNWK87EZWhi7JWj1v7ZXf94= -go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U= -go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 h1:IJFEoHiytixx8cMiVAO+GmHR6Frwu+u5Ur8njpFO6Ac= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0/go.mod h1:3rHrKNtLIoS0oZwkY2vxi+oJcwFRWdtUyRII+so45p8= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 h1:9kV11HXBHZAvuPUZxmMWrH8hZn/6UnHX4K0mu36vNsU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0/go.mod h1:JyA0FHXe22E1NeNiHmVp7kFHglnexDQ7uRWDiiJ1hKQ= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 h1:yd02MEjBdJkG3uabWP9apV+OuWRIXGDuJEUJbOHmCFU= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0/go.mod h1:umTcuxiv1n/s/S6/c2AT/g2CQ7u5C59sHDNmfSwgz7Q= +go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw= +go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 h1:Vh5HayB/0HHfOQA7Ctx69E/Y/DcQSMPpKANYVMQ7fBA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0/go.mod h1:cpgtDBaqD/6ok/UG0jT15/uKjAY8mRA53diogHBg3UI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 h1:5pojmb1U1AogINhN3SurB+zm/nIcusopeBNp42f45QM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0/go.mod h1:57gTHJSE5S1tqg+EKsLPlTWhpHMsWlVmer+LA926XiA= go.opentelemetry.io/otel/exporters/prometheus v0.52.0 h1:kmU3H0b9ufFSi8IQCcxack+sWUblKkFbqWYs6YiACGQ= go.opentelemetry.io/otel/exporters/prometheus v0.52.0/go.mod h1:+wsAp2+JhuGXX7YRkjlkx6hyWY3ogFPfNA4x3nyiAh0= -go.opentelemetry.io/otel/exporters/zipkin v1.32.0 h1:6O8HgLHPXtXE9QEKEWkBImL9mEKCGEl+m+OncVO53go= -go.opentelemetry.io/otel/exporters/zipkin v1.32.0/go.mod h1:+MFvorlowjy0iWnsKaNxC1kzczSxe71mw85h4p8yEvg= -go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M= -go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8= -go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4= -go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU= +go.opentelemetry.io/otel/exporters/zipkin v1.33.0 h1:aFexjEJIw5kVz6vQwnsqCG/nTV/UpsZh7MtQwGmH1eI= +go.opentelemetry.io/otel/exporters/zipkin v1.33.0/go.mod h1:aYsOzr/SZwZXJM6DJmSP/ST2P7MYxuc0R9RewkFVp9s= +go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ= +go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M= +go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM= +go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM= go.opentelemetry.io/otel/sdk/metric v1.30.0 h1:QJLT8Pe11jyHBHfSAgYH7kEmT24eX792jZO1bo4BXkM= go.opentelemetry.io/otel/sdk/metric v1.30.0/go.mod h1:waS6P3YqFNzeP01kuo/MBBYqaoBJl7efRQHOaydhy1Y= -go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM= -go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8= -go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= -go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s= +go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck= +go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1jgeg= +go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -245,10 +247,6 @@ go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= -gofr.dev v1.28.0 h1:bXeUtLnfZlS69+c6+y1MO2SqeXoPPGOzxE92t1yZYj8= -gofr.dev v1.28.0/go.mod h1:cQnVM+j8UFc8dM2VzNdJWU5GJMN5YWNsqPs44SsZxfY= -gofr.dev/pkg/gofr/datasource/file/ftp v0.1.0 h1:543791JYpNfB2Q76Ey9N5CQW5bIo6dlhVwvMdb+6Oow= -gofr.dev/pkg/gofr/datasource/file/ftp v0.1.0/go.mod h1:Pau/kQnk86g7U3Nwuc5/g05PaPFxfn4VFXmOa8Z4xrM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -281,8 +279,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= @@ -346,28 +344,28 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.209.0 h1:Ja2OXNlyRlWCWu8o+GgI4yUn/wz9h/5ZfFbKz+dQX+w= -google.golang.org/api v0.209.0/go.mod h1:I53S168Yr/PNDNMi5yPnDc0/LGRZO6o7PoEbl/HY3CM= +google.golang.org/api v0.212.0 h1:BcRj3MJfHF3FYD29rk7u9kuu1SyfGqfHcA0hSwKqkHg= +google.golang.org/api v0.212.0/go.mod h1:gICpLlpp12/E8mycRMzgy3SQ9cFh2XnVJ6vJi/kQbvI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f h1:zDoHYmMzMacIdjNe+P2XiTmPsLawi/pCbSPfxt6lTfw= -google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f/go.mod h1:Q5m6g8b5KaFFzsQFIGdJkSJDGeJiybVenoYFMMa3ohI= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f h1:C1QccEa9kUwvMgEUORqQD9S17QesQijxjZ84sO82mfo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk= +google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc= +google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q= +google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 h1:8ZmaLZE4XWrtU3MyClkYqqtl6Oegr3235h7jxsDyqCY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= -google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0= +google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -377,8 +375,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -411,8 +409,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.34.1 h1:u3Yi6M0N8t9yKRDwhXcyp1eS5/ErhPTBggxWFuR6Hfk= -modernc.org/sqlite v1.34.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k= +modernc.org/sqlite v1.34.2 h1:J9n76TPsfYYkFkZ9Uy1QphILYifiVEwwOT7yP5b++2Y= +modernc.org/sqlite v1.34.2/go.mod h1:dnR723UrTtjKpoHCAMN0Q/gZ9MT4r+iRvIBb9umWFkU= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= diff --git a/examples/using-add-filestore/main.go b/examples/using-add-filestore/main.go index 9a472226d..84133539c 100644 --- a/examples/using-add-filestore/main.go +++ b/examples/using-add-filestore/main.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "io/fs" "strconv" "strings" "gofr.dev/pkg/gofr" - "gofr.dev/pkg/gofr/datasource/file" + "gofr.dev/pkg/gofr/datasource" "gofr.dev/pkg/gofr/datasource/file/ftp" ) @@ -90,7 +91,7 @@ func rmCommandHandler(c *gofr.Context) (interface{}, error) { } // This can be a common function to configure both FTP and SFTP server. -func configureFileServer(app *gofr.App) file.FileSystemProvider { +func configureFileServer(app *gofr.App) datasource.FileSystemProvider { port, _ := strconv.Atoi(app.Config.Get("PORT")) return ftp.New(&ftp.Config{ @@ -102,13 +103,13 @@ func configureFileServer(app *gofr.App) file.FileSystemProvider { }) } -func printFiles(files []file.FileInfo) { +func printFiles(files []fs.FileInfo) { for _, f := range files { fmt.Println(f.Name()) } } -func grepFiles(files []file.FileInfo, keyword string) { +func grepFiles(files []fs.FileInfo, keyword string) { for _, f := range files { if strings.HasPrefix(f.Name(), keyword) { fmt.Println(f.Name()) diff --git a/pkg/gofr/external_db.go b/pkg/gofr/external_db.go index 05625271e..063e1318a 100644 --- a/pkg/gofr/external_db.go +++ b/pkg/gofr/external_db.go @@ -41,7 +41,7 @@ func (a *App) AddPubSub(pubsub container.PubSubProvider) { a.container.PubSub = pubsub } -// AddFile sets the FTP,SFTP,S3 datasource in the app's container. +// AddFileStore sets the FTP,SFTP,S3 datasource in the app's container. func (a *App) AddFileStore(fs datasource.FileSystemProvider) { fs.UseLogger(a.Logger()) fs.UseMetrics(a.Metrics()) From b3e8848dc16f380541db2812961db7c7c9b95ed6 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Fri, 20 Dec 2024 10:54:48 +0530 Subject: [PATCH 6/7] resolve linters --- pkg/gofr/container/mock_container.go | 4 +- pkg/gofr/datasource/file/fs.go | 2 +- pkg/gofr/datasource/file/fs_test.go | 2 +- pkg/gofr/datasource/file/ftp/file.go | 2 +- pkg/gofr/datasource/file/mock_interface.go | 257 ++------- pkg/gofr/datasource/interface.go | 2 +- pkg/gofr/datasource/mock_interface.go | 626 +++++++++++++++++++++ pkg/gofr/external_db_test.go | 8 +- pkg/gofr/file_handler.go | 12 +- 9 files changed, 687 insertions(+), 228 deletions(-) create mode 100644 pkg/gofr/datasource/mock_interface.go diff --git a/pkg/gofr/container/mock_container.go b/pkg/gofr/container/mock_container.go index 02959c6d4..9d2959751 100644 --- a/pkg/gofr/container/mock_container.go +++ b/pkg/gofr/container/mock_container.go @@ -24,7 +24,7 @@ type Mocks struct { KVStore *MockKVStore DGraph *MockDgraph OpenTSDB *MockOpenTSDBProvider - File *file.MockFileSystemProvider + File *file.MockFileSystem HTTPService *service.MockHTTP Metrics *MockMetrics } @@ -77,7 +77,7 @@ func NewMockContainer(t *testing.T, options ...options) (*Container, *Mocks) { kvStoreMock := NewMockKVStore(ctrl) container.KVStore = kvStoreMock - fileStoreMock := file.NewMockFileSystemProvider(ctrl) + fileStoreMock := file.NewMockFileSystem(ctrl) container.File = fileStoreMock dgraphMock := NewMockDgraph(ctrl) diff --git a/pkg/gofr/datasource/file/fs.go b/pkg/gofr/datasource/file/fs.go index 55c8075db..2657320aa 100644 --- a/pkg/gofr/datasource/file/fs.go +++ b/pkg/gofr/datasource/file/fs.go @@ -20,7 +20,7 @@ func New(logger datasource.Logger) *FileSys { // Create creates or truncates the named file. If the file already exists, it is truncated. // If the file does not exist, it is created with mode 666. // If successful, methods on the returned File can be used for I/ O; the associated file descriptor has mode O_RDWR. -// If there is an error, it will be of type *PathError +// If there is an error, it will be of type *PathError. func (f *FileSys) Create(name string) (File, error) { newFile, err := os.Create(name) if err != nil { diff --git a/pkg/gofr/datasource/file/fs_test.go b/pkg/gofr/datasource/file/fs_test.go index 33cb72646..8416a14ce 100644 --- a/pkg/gofr/datasource/file/fs_test.go +++ b/pkg/gofr/datasource/file/fs_test.go @@ -65,7 +65,7 @@ func Test_CreateReadDeleteFile(t *testing.T) { fi, err := fileStore.Create(fileName) newFile := fi.(*file) - _, _ = newFile.Write([]byte("some content")) + _, _ = newFile.WriteString("some content") defer func(fileStore *FileSys, name string) { _ = fileStore.Remove(name) diff --git a/pkg/gofr/datasource/file/ftp/file.go b/pkg/gofr/datasource/file/ftp/file.go index 6259c7648..bc622826e 100644 --- a/pkg/gofr/datasource/file/ftp/file.go +++ b/pkg/gofr/datasource/file/ftp/file.go @@ -49,7 +49,7 @@ type jsonReader struct { token json.Token } -func (f *File) Sys() any { +func (*File) Sys() any { return "ftp" } diff --git a/pkg/gofr/datasource/file/mock_interface.go b/pkg/gofr/datasource/file/mock_interface.go index 76ab5a7a8..102bdc0d9 100644 --- a/pkg/gofr/datasource/file/mock_interface.go +++ b/pkg/gofr/datasource/file/mock_interface.go @@ -10,6 +10,7 @@ package file import ( + fs "io/fs" os "os" reflect "reflect" @@ -217,172 +218,22 @@ func (m *MockFileSystem) EXPECT() *MockFileSystemMockRecorder { return m.recorder } -// Create mocks base method. -func (m *MockFileSystem) Create(name string) (File, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", name) - ret0, _ := ret[0].(File) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Create indicates an expected call of Create. -func (mr *MockFileSystemMockRecorder) Create(name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFileSystem)(nil).Create), name) -} - -// Mkdir mocks base method. -func (m *MockFileSystem) Mkdir(name string, perm os.FileMode) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Mkdir", name, perm) - ret0, _ := ret[0].(error) - return ret0 -} - -// Mkdir indicates an expected call of Mkdir. -func (mr *MockFileSystemMockRecorder) Mkdir(name, perm any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdir", reflect.TypeOf((*MockFileSystem)(nil).Mkdir), name, perm) -} - -// MkdirAll mocks base method. -func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MkdirAll", path, perm) - ret0, _ := ret[0].(error) - return ret0 -} - -// MkdirAll indicates an expected call of MkdirAll. -func (mr *MockFileSystemMockRecorder) MkdirAll(path, perm any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MkdirAll", reflect.TypeOf((*MockFileSystem)(nil).MkdirAll), path, perm) -} - -// Open mocks base method. -func (m *MockFileSystem) Open(name string) (File, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Open", name) - ret0, _ := ret[0].(File) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Open indicates an expected call of Open. -func (mr *MockFileSystemMockRecorder) Open(name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFileSystem)(nil).Open), name) -} - -// OpenFile mocks base method. -func (m *MockFileSystem) OpenFile(name string, flag int, perm os.FileMode) (File, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "OpenFile", name, flag, perm) - ret0, _ := ret[0].(File) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// OpenFile indicates an expected call of OpenFile. -func (mr *MockFileSystemMockRecorder) OpenFile(name, flag, perm any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenFile", reflect.TypeOf((*MockFileSystem)(nil).OpenFile), name, flag, perm) -} - -// Remove mocks base method. -func (m *MockFileSystem) Remove(name string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Remove", name) - ret0, _ := ret[0].(error) - return ret0 -} - -// Remove indicates an expected call of Remove. -func (mr *MockFileSystemMockRecorder) Remove(name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockFileSystem)(nil).Remove), name) -} - -// RemoveAll mocks base method. -func (m *MockFileSystem) RemoveAll(path string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RemoveAll", path) - ret0, _ := ret[0].(error) - return ret0 -} - -// RemoveAll indicates an expected call of RemoveAll. -func (mr *MockFileSystemMockRecorder) RemoveAll(path any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveAll", reflect.TypeOf((*MockFileSystem)(nil).RemoveAll), path) -} - -// Rename mocks base method. -func (m *MockFileSystem) Rename(oldname, newname string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Rename", oldname, newname) - ret0, _ := ret[0].(error) - return ret0 -} - -// Rename indicates an expected call of Rename. -func (mr *MockFileSystemMockRecorder) Rename(oldname, newname any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rename", reflect.TypeOf((*MockFileSystem)(nil).Rename), oldname, newname) -} - -// MockFileSystemProvider is a mock of FileSystemProvider interface. -type MockFileSystemProvider struct { - ctrl *gomock.Controller - recorder *MockFileSystemProviderMockRecorder -} - -// MockFileSystemProviderMockRecorder is the mock recorder for MockFileSystemProvider. -type MockFileSystemProviderMockRecorder struct { - mock *MockFileSystemProvider -} - -// NewMockFileSystemProvider creates a new mock instance. -func NewMockFileSystemProvider(ctrl *gomock.Controller) *MockFileSystemProvider { - mock := &MockFileSystemProvider{ctrl: ctrl} - mock.recorder = &MockFileSystemProviderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockFileSystemProvider) EXPECT() *MockFileSystemProviderMockRecorder { - return m.recorder -} - // ChDir mocks base method. -func (m *MockFileSystemProvider) ChDir(arg0 string) error { +func (m *MockFileSystem) ChDir(dirname string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ChDir", arg0) + ret := m.ctrl.Call(m, "ChDir", dirname) ret0, _ := ret[0].(error) return ret0 } // ChDir indicates an expected call of ChDir. -func (mr *MockFileSystemProviderMockRecorder) ChDir(arg0 any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) ChDir(dirname any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChDir", reflect.TypeOf((*MockFileSystemProvider)(nil).ChDir), arg0) -} - -// Connect mocks base method. -func (m *MockFileSystemProvider) Connect() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Connect") -} - -// Connect indicates an expected call of Connect. -func (mr *MockFileSystemProviderMockRecorder) Connect() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Connect", reflect.TypeOf((*MockFileSystemProvider)(nil).Connect)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChDir", reflect.TypeOf((*MockFileSystem)(nil).ChDir), dirname) } // Create mocks base method. -func (m *MockFileSystemProvider) Create(name string) (File, error) { +func (m *MockFileSystem) Create(name string) (File, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Create", name) ret0, _ := ret[0].(File) @@ -391,13 +242,13 @@ func (m *MockFileSystemProvider) Create(name string) (File, error) { } // Create indicates an expected call of Create. -func (mr *MockFileSystemProviderMockRecorder) Create(name any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Create(name any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFileSystemProvider)(nil).Create), name) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFileSystem)(nil).Create), name) } // Getwd mocks base method. -func (m *MockFileSystemProvider) Getwd() (string, error) { +func (m *MockFileSystem) Getwd() (string, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Getwd") ret0, _ := ret[0].(string) @@ -406,13 +257,13 @@ func (m *MockFileSystemProvider) Getwd() (string, error) { } // Getwd indicates an expected call of Getwd. -func (mr *MockFileSystemProviderMockRecorder) Getwd() *gomock.Call { +func (mr *MockFileSystemMockRecorder) Getwd() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Getwd", reflect.TypeOf((*MockFileSystemProvider)(nil).Getwd)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Getwd", reflect.TypeOf((*MockFileSystem)(nil).Getwd)) } // Mkdir mocks base method. -func (m *MockFileSystemProvider) Mkdir(name string, perm os.FileMode) error { +func (m *MockFileSystem) Mkdir(name string, perm os.FileMode) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Mkdir", name, perm) ret0, _ := ret[0].(error) @@ -420,13 +271,13 @@ func (m *MockFileSystemProvider) Mkdir(name string, perm os.FileMode) error { } // Mkdir indicates an expected call of Mkdir. -func (mr *MockFileSystemProviderMockRecorder) Mkdir(name, perm any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Mkdir(name, perm any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdir", reflect.TypeOf((*MockFileSystemProvider)(nil).Mkdir), name, perm) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdir", reflect.TypeOf((*MockFileSystem)(nil).Mkdir), name, perm) } // MkdirAll mocks base method. -func (m *MockFileSystemProvider) MkdirAll(path string, perm os.FileMode) error { +func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MkdirAll", path, perm) ret0, _ := ret[0].(error) @@ -434,13 +285,13 @@ func (m *MockFileSystemProvider) MkdirAll(path string, perm os.FileMode) error { } // MkdirAll indicates an expected call of MkdirAll. -func (mr *MockFileSystemProviderMockRecorder) MkdirAll(path, perm any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) MkdirAll(path, perm any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MkdirAll", reflect.TypeOf((*MockFileSystemProvider)(nil).MkdirAll), path, perm) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MkdirAll", reflect.TypeOf((*MockFileSystem)(nil).MkdirAll), path, perm) } // Open mocks base method. -func (m *MockFileSystemProvider) Open(name string) (File, error) { +func (m *MockFileSystem) Open(name string) (File, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Open", name) ret0, _ := ret[0].(File) @@ -449,13 +300,13 @@ func (m *MockFileSystemProvider) Open(name string) (File, error) { } // Open indicates an expected call of Open. -func (mr *MockFileSystemProviderMockRecorder) Open(name any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Open(name any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFileSystemProvider)(nil).Open), name) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFileSystem)(nil).Open), name) } // OpenFile mocks base method. -func (m *MockFileSystemProvider) OpenFile(name string, flag int, perm os.FileMode) (File, error) { +func (m *MockFileSystem) OpenFile(name string, flag int, perm os.FileMode) (File, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "OpenFile", name, flag, perm) ret0, _ := ret[0].(File) @@ -464,28 +315,28 @@ func (m *MockFileSystemProvider) OpenFile(name string, flag int, perm os.FileMod } // OpenFile indicates an expected call of OpenFile. -func (mr *MockFileSystemProviderMockRecorder) OpenFile(name, flag, perm any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) OpenFile(name, flag, perm any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenFile", reflect.TypeOf((*MockFileSystemProvider)(nil).OpenFile), name, flag, perm) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenFile", reflect.TypeOf((*MockFileSystem)(nil).OpenFile), name, flag, perm) } // ReadDir mocks base method. -func (m *MockFileSystemProvider) ReadDir(arg0 string) ([]FileInfo, error) { +func (m *MockFileSystem) ReadDir(dir string) ([]fs.FileInfo, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReadDir", arg0) - ret0, _ := ret[0].([]FileInfo) + ret := m.ctrl.Call(m, "ReadDir", dir) + ret0, _ := ret[0].([]fs.FileInfo) ret1, _ := ret[1].(error) return ret0, ret1 } // ReadDir indicates an expected call of ReadDir. -func (mr *MockFileSystemProviderMockRecorder) ReadDir(arg0 any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) ReadDir(dir any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDir", reflect.TypeOf((*MockFileSystemProvider)(nil).ReadDir), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDir", reflect.TypeOf((*MockFileSystem)(nil).ReadDir), dir) } // Remove mocks base method. -func (m *MockFileSystemProvider) Remove(name string) error { +func (m *MockFileSystem) Remove(name string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Remove", name) ret0, _ := ret[0].(error) @@ -493,13 +344,13 @@ func (m *MockFileSystemProvider) Remove(name string) error { } // Remove indicates an expected call of Remove. -func (mr *MockFileSystemProviderMockRecorder) Remove(name any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Remove(name any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockFileSystemProvider)(nil).Remove), name) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockFileSystem)(nil).Remove), name) } // RemoveAll mocks base method. -func (m *MockFileSystemProvider) RemoveAll(path string) error { +func (m *MockFileSystem) RemoveAll(path string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RemoveAll", path) ret0, _ := ret[0].(error) @@ -507,13 +358,13 @@ func (m *MockFileSystemProvider) RemoveAll(path string) error { } // RemoveAll indicates an expected call of RemoveAll. -func (mr *MockFileSystemProviderMockRecorder) RemoveAll(path any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) RemoveAll(path any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveAll", reflect.TypeOf((*MockFileSystemProvider)(nil).RemoveAll), path) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveAll", reflect.TypeOf((*MockFileSystem)(nil).RemoveAll), path) } // Rename mocks base method. -func (m *MockFileSystemProvider) Rename(oldname, newname string) error { +func (m *MockFileSystem) Rename(oldname, newname string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Rename", oldname, newname) ret0, _ := ret[0].(error) @@ -521,46 +372,22 @@ func (m *MockFileSystemProvider) Rename(oldname, newname string) error { } // Rename indicates an expected call of Rename. -func (mr *MockFileSystemProviderMockRecorder) Rename(oldname, newname any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Rename(oldname, newname any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rename", reflect.TypeOf((*MockFileSystemProvider)(nil).Rename), oldname, newname) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rename", reflect.TypeOf((*MockFileSystem)(nil).Rename), oldname, newname) } // Stat mocks base method. -func (m *MockFileSystemProvider) Stat(arg0 string) (FileInfo, error) { +func (m *MockFileSystem) Stat(name string) (fs.FileInfo, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Stat", arg0) - ret0, _ := ret[0].(FileInfo) + ret := m.ctrl.Call(m, "Stat", name) + ret0, _ := ret[0].(fs.FileInfo) ret1, _ := ret[1].(error) return ret0, ret1 } // Stat indicates an expected call of Stat. -func (mr *MockFileSystemProviderMockRecorder) Stat(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stat", reflect.TypeOf((*MockFileSystemProvider)(nil).Stat), arg0) -} - -// UseLogger mocks base method. -func (m *MockFileSystemProvider) UseLogger(logger any) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "UseLogger", logger) -} - -// UseLogger indicates an expected call of UseLogger. -func (mr *MockFileSystemProviderMockRecorder) UseLogger(logger any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UseLogger", reflect.TypeOf((*MockFileSystemProvider)(nil).UseLogger), logger) -} - -// UseMetrics mocks base method. -func (m *MockFileSystemProvider) UseMetrics(metrics any) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "UseMetrics", metrics) -} - -// UseMetrics indicates an expected call of UseMetrics. -func (mr *MockFileSystemProviderMockRecorder) UseMetrics(metrics any) *gomock.Call { +func (mr *MockFileSystemMockRecorder) Stat(name any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UseMetrics", reflect.TypeOf((*MockFileSystemProvider)(nil).UseMetrics), metrics) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stat", reflect.TypeOf((*MockFileSystem)(nil).Stat), name) } diff --git a/pkg/gofr/datasource/interface.go b/pkg/gofr/datasource/interface.go index 5bc5e18ef..907751477 100644 --- a/pkg/gofr/datasource/interface.go +++ b/pkg/gofr/datasource/interface.go @@ -29,7 +29,7 @@ type FileSystem interface { // error, if any happens. Create(name string) (any, error) - //TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations + // TODO - Lets make bucket constant for MkdirAll as well, we might create buckets from migrations // Mkdir creates a directory in the filesystem, return an error if any // happens. diff --git a/pkg/gofr/datasource/mock_interface.go b/pkg/gofr/datasource/mock_interface.go new file mode 100644 index 000000000..26090afd9 --- /dev/null +++ b/pkg/gofr/datasource/mock_interface.go @@ -0,0 +1,626 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: interface.go +// +// Generated by this command: +// +// mockgen -source=interface.go -destination=mock_interface.go -package=datasource +// + +// Package datasource is a generated GoMock package. +package datasource + +import ( + fs "io/fs" + os "os" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockFile is a mock of File interface. +type MockFile struct { + ctrl *gomock.Controller + recorder *MockFileMockRecorder +} + +// MockFileMockRecorder is the mock recorder for MockFile. +type MockFileMockRecorder struct { + mock *MockFile +} + +// NewMockFile creates a new mock instance. +func NewMockFile(ctrl *gomock.Controller) *MockFile { + mock := &MockFile{ctrl: ctrl} + mock.recorder = &MockFileMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFile) EXPECT() *MockFileMockRecorder { + return m.recorder +} + +// Close mocks base method. +func (m *MockFile) Close() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockFileMockRecorder) Close() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockFile)(nil).Close)) +} + +// Read mocks base method. +func (m *MockFile) Read(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockFileMockRecorder) Read(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockFile)(nil).Read), p) +} + +// ReadAll mocks base method. +func (m *MockFile) ReadAll() (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadAll") + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadAll indicates an expected call of ReadAll. +func (mr *MockFileMockRecorder) ReadAll() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadAll", reflect.TypeOf((*MockFile)(nil).ReadAll)) +} + +// ReadAt mocks base method. +func (m *MockFile) ReadAt(p []byte, off int64) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadAt", p, off) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadAt indicates an expected call of ReadAt. +func (mr *MockFileMockRecorder) ReadAt(p, off any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadAt", reflect.TypeOf((*MockFile)(nil).ReadAt), p, off) +} + +// Seek mocks base method. +func (m *MockFile) Seek(offset int64, whence int) (int64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seek", offset, whence) + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Seek indicates an expected call of Seek. +func (mr *MockFileMockRecorder) Seek(offset, whence any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seek", reflect.TypeOf((*MockFile)(nil).Seek), offset, whence) +} + +// Write mocks base method. +func (m *MockFile) Write(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Write", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Write indicates an expected call of Write. +func (mr *MockFileMockRecorder) Write(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockFile)(nil).Write), p) +} + +// WriteAt mocks base method. +func (m *MockFile) WriteAt(p []byte, off int64) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WriteAt", p, off) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// WriteAt indicates an expected call of WriteAt. +func (mr *MockFileMockRecorder) WriteAt(p, off any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteAt", reflect.TypeOf((*MockFile)(nil).WriteAt), p, off) +} + +// MockRowReader is a mock of RowReader interface. +type MockRowReader struct { + ctrl *gomock.Controller + recorder *MockRowReaderMockRecorder +} + +// MockRowReaderMockRecorder is the mock recorder for MockRowReader. +type MockRowReaderMockRecorder struct { + mock *MockRowReader +} + +// NewMockRowReader creates a new mock instance. +func NewMockRowReader(ctrl *gomock.Controller) *MockRowReader { + mock := &MockRowReader{ctrl: ctrl} + mock.recorder = &MockRowReaderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRowReader) EXPECT() *MockRowReaderMockRecorder { + return m.recorder +} + +// Next mocks base method. +func (m *MockRowReader) Next() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Next") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Next indicates an expected call of Next. +func (mr *MockRowReaderMockRecorder) Next() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Next", reflect.TypeOf((*MockRowReader)(nil).Next)) +} + +// Scan mocks base method. +func (m *MockRowReader) Scan(arg0 any) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Scan", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Scan indicates an expected call of Scan. +func (mr *MockRowReaderMockRecorder) Scan(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Scan", reflect.TypeOf((*MockRowReader)(nil).Scan), arg0) +} + +// MockFileSystem is a mock of FileSystem interface. +type MockFileSystem struct { + ctrl *gomock.Controller + recorder *MockFileSystemMockRecorder +} + +// MockFileSystemMockRecorder is the mock recorder for MockFileSystem. +type MockFileSystemMockRecorder struct { + mock *MockFileSystem +} + +// NewMockFileSystem creates a new mock instance. +func NewMockFileSystem(ctrl *gomock.Controller) *MockFileSystem { + mock := &MockFileSystem{ctrl: ctrl} + mock.recorder = &MockFileSystemMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFileSystem) EXPECT() *MockFileSystemMockRecorder { + return m.recorder +} + +// ChDir mocks base method. +func (m *MockFileSystem) ChDir(dirname string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChDir", dirname) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChDir indicates an expected call of ChDir. +func (mr *MockFileSystemMockRecorder) ChDir(dirname any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChDir", reflect.TypeOf((*MockFileSystem)(nil).ChDir), dirname) +} + +// Create mocks base method. +func (m *MockFileSystem) Create(name string) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", name) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockFileSystemMockRecorder) Create(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFileSystem)(nil).Create), name) +} + +// Getwd mocks base method. +func (m *MockFileSystem) Getwd() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Getwd") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Getwd indicates an expected call of Getwd. +func (mr *MockFileSystemMockRecorder) Getwd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Getwd", reflect.TypeOf((*MockFileSystem)(nil).Getwd)) +} + +// Mkdir mocks base method. +func (m *MockFileSystem) Mkdir(name string, perm os.FileMode) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Mkdir", name, perm) + ret0, _ := ret[0].(error) + return ret0 +} + +// Mkdir indicates an expected call of Mkdir. +func (mr *MockFileSystemMockRecorder) Mkdir(name, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdir", reflect.TypeOf((*MockFileSystem)(nil).Mkdir), name, perm) +} + +// MkdirAll mocks base method. +func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MkdirAll", path, perm) + ret0, _ := ret[0].(error) + return ret0 +} + +// MkdirAll indicates an expected call of MkdirAll. +func (mr *MockFileSystemMockRecorder) MkdirAll(path, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MkdirAll", reflect.TypeOf((*MockFileSystem)(nil).MkdirAll), path, perm) +} + +// Open mocks base method. +func (m *MockFileSystem) Open(name string) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Open", name) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Open indicates an expected call of Open. +func (mr *MockFileSystemMockRecorder) Open(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFileSystem)(nil).Open), name) +} + +// OpenFile mocks base method. +func (m *MockFileSystem) OpenFile(name string, flag int, perm os.FileMode) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OpenFile", name, flag, perm) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// OpenFile indicates an expected call of OpenFile. +func (mr *MockFileSystemMockRecorder) OpenFile(name, flag, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenFile", reflect.TypeOf((*MockFileSystem)(nil).OpenFile), name, flag, perm) +} + +// ReadDir mocks base method. +func (m *MockFileSystem) ReadDir(dir string) ([]fs.FileInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadDir", dir) + ret0, _ := ret[0].([]fs.FileInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadDir indicates an expected call of ReadDir. +func (mr *MockFileSystemMockRecorder) ReadDir(dir any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDir", reflect.TypeOf((*MockFileSystem)(nil).ReadDir), dir) +} + +// Remove mocks base method. +func (m *MockFileSystem) Remove(name string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Remove", name) + ret0, _ := ret[0].(error) + return ret0 +} + +// Remove indicates an expected call of Remove. +func (mr *MockFileSystemMockRecorder) Remove(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockFileSystem)(nil).Remove), name) +} + +// RemoveAll mocks base method. +func (m *MockFileSystem) RemoveAll(path string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveAll", path) + ret0, _ := ret[0].(error) + return ret0 +} + +// RemoveAll indicates an expected call of RemoveAll. +func (mr *MockFileSystemMockRecorder) RemoveAll(path any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveAll", reflect.TypeOf((*MockFileSystem)(nil).RemoveAll), path) +} + +// Rename mocks base method. +func (m *MockFileSystem) Rename(oldname, newname string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Rename", oldname, newname) + ret0, _ := ret[0].(error) + return ret0 +} + +// Rename indicates an expected call of Rename. +func (mr *MockFileSystemMockRecorder) Rename(oldname, newname any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rename", reflect.TypeOf((*MockFileSystem)(nil).Rename), oldname, newname) +} + +// Stat mocks base method. +func (m *MockFileSystem) Stat(name string) (fs.FileInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Stat", name) + ret0, _ := ret[0].(fs.FileInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Stat indicates an expected call of Stat. +func (mr *MockFileSystemMockRecorder) Stat(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stat", reflect.TypeOf((*MockFileSystem)(nil).Stat), name) +} + +// MockFileSystemProvider is a mock of FileSystemProvider interface. +type MockFileSystemProvider struct { + ctrl *gomock.Controller + recorder *MockFileSystemProviderMockRecorder +} + +// MockFileSystemProviderMockRecorder is the mock recorder for MockFileSystemProvider. +type MockFileSystemProviderMockRecorder struct { + mock *MockFileSystemProvider +} + +// NewMockFileSystemProvider creates a new mock instance. +func NewMockFileSystemProvider(ctrl *gomock.Controller) *MockFileSystemProvider { + mock := &MockFileSystemProvider{ctrl: ctrl} + mock.recorder = &MockFileSystemProviderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFileSystemProvider) EXPECT() *MockFileSystemProviderMockRecorder { + return m.recorder +} + +// ChDir mocks base method. +func (m *MockFileSystemProvider) ChDir(dirname string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChDir", dirname) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChDir indicates an expected call of ChDir. +func (mr *MockFileSystemProviderMockRecorder) ChDir(dirname any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChDir", reflect.TypeOf((*MockFileSystemProvider)(nil).ChDir), dirname) +} + +// Connect mocks base method. +func (m *MockFileSystemProvider) Connect() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Connect") +} + +// Connect indicates an expected call of Connect. +func (mr *MockFileSystemProviderMockRecorder) Connect() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Connect", reflect.TypeOf((*MockFileSystemProvider)(nil).Connect)) +} + +// Create mocks base method. +func (m *MockFileSystemProvider) Create(name string) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", name) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockFileSystemProviderMockRecorder) Create(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFileSystemProvider)(nil).Create), name) +} + +// Getwd mocks base method. +func (m *MockFileSystemProvider) Getwd() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Getwd") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Getwd indicates an expected call of Getwd. +func (mr *MockFileSystemProviderMockRecorder) Getwd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Getwd", reflect.TypeOf((*MockFileSystemProvider)(nil).Getwd)) +} + +// Mkdir mocks base method. +func (m *MockFileSystemProvider) Mkdir(name string, perm os.FileMode) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Mkdir", name, perm) + ret0, _ := ret[0].(error) + return ret0 +} + +// Mkdir indicates an expected call of Mkdir. +func (mr *MockFileSystemProviderMockRecorder) Mkdir(name, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdir", reflect.TypeOf((*MockFileSystemProvider)(nil).Mkdir), name, perm) +} + +// MkdirAll mocks base method. +func (m *MockFileSystemProvider) MkdirAll(path string, perm os.FileMode) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MkdirAll", path, perm) + ret0, _ := ret[0].(error) + return ret0 +} + +// MkdirAll indicates an expected call of MkdirAll. +func (mr *MockFileSystemProviderMockRecorder) MkdirAll(path, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MkdirAll", reflect.TypeOf((*MockFileSystemProvider)(nil).MkdirAll), path, perm) +} + +// Open mocks base method. +func (m *MockFileSystemProvider) Open(name string) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Open", name) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Open indicates an expected call of Open. +func (mr *MockFileSystemProviderMockRecorder) Open(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFileSystemProvider)(nil).Open), name) +} + +// OpenFile mocks base method. +func (m *MockFileSystemProvider) OpenFile(name string, flag int, perm os.FileMode) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OpenFile", name, flag, perm) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// OpenFile indicates an expected call of OpenFile. +func (mr *MockFileSystemProviderMockRecorder) OpenFile(name, flag, perm any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenFile", reflect.TypeOf((*MockFileSystemProvider)(nil).OpenFile), name, flag, perm) +} + +// ReadDir mocks base method. +func (m *MockFileSystemProvider) ReadDir(dir string) ([]fs.FileInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadDir", dir) + ret0, _ := ret[0].([]fs.FileInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadDir indicates an expected call of ReadDir. +func (mr *MockFileSystemProviderMockRecorder) ReadDir(dir any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDir", reflect.TypeOf((*MockFileSystemProvider)(nil).ReadDir), dir) +} + +// Remove mocks base method. +func (m *MockFileSystemProvider) Remove(name string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Remove", name) + ret0, _ := ret[0].(error) + return ret0 +} + +// Remove indicates an expected call of Remove. +func (mr *MockFileSystemProviderMockRecorder) Remove(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockFileSystemProvider)(nil).Remove), name) +} + +// RemoveAll mocks base method. +func (m *MockFileSystemProvider) RemoveAll(path string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveAll", path) + ret0, _ := ret[0].(error) + return ret0 +} + +// RemoveAll indicates an expected call of RemoveAll. +func (mr *MockFileSystemProviderMockRecorder) RemoveAll(path any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveAll", reflect.TypeOf((*MockFileSystemProvider)(nil).RemoveAll), path) +} + +// Rename mocks base method. +func (m *MockFileSystemProvider) Rename(oldname, newname string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Rename", oldname, newname) + ret0, _ := ret[0].(error) + return ret0 +} + +// Rename indicates an expected call of Rename. +func (mr *MockFileSystemProviderMockRecorder) Rename(oldname, newname any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rename", reflect.TypeOf((*MockFileSystemProvider)(nil).Rename), oldname, newname) +} + +// Stat mocks base method. +func (m *MockFileSystemProvider) Stat(name string) (fs.FileInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Stat", name) + ret0, _ := ret[0].(fs.FileInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Stat indicates an expected call of Stat. +func (mr *MockFileSystemProviderMockRecorder) Stat(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stat", reflect.TypeOf((*MockFileSystemProvider)(nil).Stat), name) +} + +// UseLogger mocks base method. +func (m *MockFileSystemProvider) UseLogger(logger any) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "UseLogger", logger) +} + +// UseLogger indicates an expected call of UseLogger. +func (mr *MockFileSystemProviderMockRecorder) UseLogger(logger any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UseLogger", reflect.TypeOf((*MockFileSystemProvider)(nil).UseLogger), logger) +} + +// UseMetrics mocks base method. +func (m *MockFileSystemProvider) UseMetrics(metrics any) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "UseMetrics", metrics) +} + +// UseMetrics indicates an expected call of UseMetrics. +func (mr *MockFileSystemProviderMockRecorder) UseMetrics(metrics any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UseMetrics", reflect.TypeOf((*MockFileSystemProvider)(nil).UseMetrics), metrics) +} diff --git a/pkg/gofr/external_db_test.go b/pkg/gofr/external_db_test.go index b16ca7da4..b2e74a66c 100644 --- a/pkg/gofr/external_db_test.go +++ b/pkg/gofr/external_db_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "gofr.dev/pkg/gofr/container" - "gofr.dev/pkg/gofr/datasource/file" + "gofr.dev/pkg/gofr/datasource" ) func TestApp_AddKVStore(t *testing.T) { @@ -98,7 +98,7 @@ func TestApp_AddFTP(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mock := file.NewMockFileSystemProvider(ctrl) + mock := datasource.NewMockFileSystemProvider(ctrl) mock.EXPECT().UseLogger(app.Logger()) mock.EXPECT().UseMetrics(app.Metrics()) @@ -115,7 +115,7 @@ func TestApp_AddFTP(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mock := file.NewMockFileSystemProvider(ctrl) + mock := datasource.NewMockFileSystemProvider(ctrl) mock.EXPECT().UseLogger(app.Logger()) mock.EXPECT().UseMetrics(app.Metrics()) @@ -134,7 +134,7 @@ func TestApp_AddS3(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mock := file.NewMockFileSystemProvider(ctrl) + mock := datasource.NewMockFileSystemProvider(ctrl) mock.EXPECT().UseLogger(app.Logger()) mock.EXPECT().UseMetrics(app.Metrics()) diff --git a/pkg/gofr/file_handler.go b/pkg/gofr/file_handler.go index 737509994..9fa906466 100644 --- a/pkg/gofr/file_handler.go +++ b/pkg/gofr/file_handler.go @@ -2,12 +2,18 @@ package gofr import ( "errors" + "fmt" "os" "gofr.dev/pkg/gofr/datasource" "gofr.dev/pkg/gofr/datasource/file" ) +var ( + ErrFailedToCreateFile = errors.New("failed to create file") + ErrFailedToOpenFile = errors.New("failed to open file") +) + // Developer Note: fileSysWrapper wraps a datasource.FileSystem to return file.File instead of an interface, // this is useful when we want to use the file.File methods, but don't want the external datasource // to be dependent on any particular version of gofr so that they can be maintained independently. @@ -20,7 +26,7 @@ func (fsW *fileSysWrapper) Create(name string) (file.File, error) { f, ok := fI.(file.File) if !ok { - return nil, errors.New("failed to create file") + return nil, fmt.Errorf("%w: %w", ErrFailedToCreateFile, err) } return f, err @@ -31,7 +37,7 @@ func (fsW *fileSysWrapper) Open(name string) (file.File, error) { f, ok := fI.(file.File) if !ok { - return nil, errors.New("failed to open file") + return nil, fmt.Errorf("%w: %w", ErrFailedToOpenFile, err) } return f, err @@ -42,7 +48,7 @@ func (fsW *fileSysWrapper) OpenFile(name string, flag int, perm os.FileMode) (fi f, ok := fI.(file.File) if !ok { - return nil, errors.New("failed to open file") + return nil, fmt.Errorf("%w: %w", ErrFailedToOpenFile, err) } return f, err From d4cca688b1908a92e1cec2b7460aee9ac04e5073 Mon Sep 17 00:00:00 2001 From: umang01-hash Date: Fri, 20 Dec 2024 12:11:07 +0530 Subject: [PATCH 7/7] fix failing tests --- pkg/gofr/external_db_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/gofr/external_db_test.go b/pkg/gofr/external_db_test.go index b2e74a66c..0446c8ba6 100644 --- a/pkg/gofr/external_db_test.go +++ b/pkg/gofr/external_db_test.go @@ -106,7 +106,7 @@ func TestApp_AddFTP(t *testing.T) { app.AddFTP(mock) - assert.Equal(t, mock, app.container.File) + assert.True(t, ctrl.Satisfied()) }) t.Run("Adding FTP", func(t *testing.T) { @@ -123,7 +123,7 @@ func TestApp_AddFTP(t *testing.T) { app.AddFileStore(mock) - assert.Equal(t, mock, app.container.File) + assert.True(t, ctrl.Satisfied()) }) } @@ -142,7 +142,7 @@ func TestApp_AddS3(t *testing.T) { app.AddFileStore(mock) - assert.Equal(t, mock, app.container.File) + assert.True(t, ctrl.Satisfied()) }) }