Documentation ¶
Overview ¶
Package iofs provides the Go 1.16+ io/fs#FS driver.
It can accept various file systems (like embed.FS, archive/zip#Reader) implementing io/fs#FS.
This driver cannot be used with Go versions 1.15 and below.
Also, Opening with a URL scheme is not supported.
Example ¶
//go:build go1.16 // +build go1.16 package main import ( "embed" "log" "github.com/golang-migrate/migrate/v4" _ "github.com/golang-migrate/migrate/v4/database/postgres" "github.com/golang-migrate/migrate/v4/source/iofs" ) //go:embed testdata/migrations/*.sql var fs embed.FS func main() { d, err := iofs.New(fs, "testdata/migrations") if err != nil { log.Fatal(err) } m, err := migrate.NewWithSourceInstance("iofs", d, "postgres://postgres@localhost/postgres?sslmode=disable") if err != nil { log.Fatal(err) } err = m.Up() if err != nil { // ... } // ... }
Output:
Index ¶
- func New(fsys fs.FS, path string) (source.Driver, error)
- type PartialDriver
- func (d *PartialDriver) Close() error
- func (d *PartialDriver) First() (version uint, err error)
- func (d *PartialDriver) Init(fsys fs.FS, path string) error
- func (d *PartialDriver) Next(version uint) (nextVersion uint, err error)
- func (d *PartialDriver) Prev(version uint) (prevVersion uint, err error)
- func (d *PartialDriver) ReadDown(version uint) (r io.ReadCloser, identifier string, err error)
- func (d *PartialDriver) ReadUp(version uint) (r io.ReadCloser, identifier string, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PartialDriver ¶
type PartialDriver struct {
// contains filtered or unexported fields
}
PartialDriver is a helper service for creating new source drivers working with io/fs.FS instances. It implements all source.Driver interface methods except for Open(). New driver could embed this struct and add missing Open() method.
To prepare PartialDriver for use Init() function.
func (*PartialDriver) Close ¶
func (d *PartialDriver) Close() error
Close is part of source.Driver interface implementation. Closes the file system if possible.
func (*PartialDriver) First ¶
func (d *PartialDriver) First() (version uint, err error)
First is part of source.Driver interface implementation.
func (*PartialDriver) Init ¶
func (d *PartialDriver) Init(fsys fs.FS, path string) error
Init prepares not initialized IoFS instance to read migrations from a io/fs#FS instance and a relative path.
func (*PartialDriver) Next ¶
func (d *PartialDriver) Next(version uint) (nextVersion uint, err error)
Next is part of source.Driver interface implementation.
func (*PartialDriver) Prev ¶
func (d *PartialDriver) Prev(version uint) (prevVersion uint, err error)
Prev is part of source.Driver interface implementation.
func (*PartialDriver) ReadDown ¶
func (d *PartialDriver) ReadDown(version uint) (r io.ReadCloser, identifier string, err error)
ReadDown is part of source.Driver interface implementation.
func (*PartialDriver) ReadUp ¶
func (d *PartialDriver) ReadUp(version uint) (r io.ReadCloser, identifier string, err error)
ReadUp is part of source.Driver interface implementation.