iofs

package
v4.17.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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/deepakd10/migrate/v4"
	_ "github.com/deepakd10/migrate/v4/database/postgres"
	"github.com/deepakd10/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 {
		// ...
	}
	// ...
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(fsys fs.FS, path string) (source.Driver, error)

New returns a new Driver from io/fs#FS and a relative path.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL