httpfs

package
v4.18.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 7 Imported by: 0

README

httpfs

Usage

This package could be used to create new migration source drivers that uses http.FileSystem to read migration files.

Struct httpfs.PartialDriver partly implements the source.Driver interface. It has all the methods except for Open(). Embedding this struct and adding Open() method allows users of this package to create new migration sources. Example:

struct mydriver {
        httpfs.PartialDriver
}

func (d *mydriver) Open(url string) (source.Driver, error) {
	var fs http.FileSystem
	var path string
	var ds mydriver

	// acquire fs and path from url
	// set-up ds if necessary

	if err := ds.Init(fs, path); err != nil {
		return nil, err
	}
	return &ds, nil
}

This package also provides a simple source.Driver implementation that works with http.FileSystem provided by the user of this package. It is created with httpfs.New() call.

Example of using http.Dir() to read migrations from sql directory:

	src, err := httpfs.New(http.Dir("sql"))
	if err != nil {
		// do something
	}
	m, err := migrate.NewWithSourceInstance("httpfs", src, "database://url")
	if err != nil {
		// do something
	}
        err = m.Up()
	...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(fs http.FileSystem, path string) (source.Driver, error)

New creates a new migrate source driver from a http.FileSystem instance and a relative path to migration files within the virtual FS.

Types

type PartialDriver

type PartialDriver struct {
	// contains filtered or unexported fields
}

PartialDriver is a helper service for creating new source drivers working with http.FileSystem 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 (p *PartialDriver) Close() error

Close is part of source.Driver interface implementation. This is a no-op.

func (*PartialDriver) First

func (p *PartialDriver) First() (version uint, err error)

First is part of source.Driver interface implementation.

func (*PartialDriver) Init

func (p *PartialDriver) Init(fs http.FileSystem, path string) error

Init prepares not initialized PartialDriver instance to read migrations from a http.FileSystem instance and a relative path.

func (*PartialDriver) Next

func (p *PartialDriver) Next(version uint) (nextVersion uint, err error)

Next is part of source.Driver interface implementation.

func (*PartialDriver) Prev

func (p *PartialDriver) Prev(version uint) (prevVersion uint, err error)

Prev is part of source.Driver interface implementation.

func (*PartialDriver) ReadDown

func (p *PartialDriver) ReadDown(version uint) (r io.ReadCloser, identifier string, err error)

ReadDown is part of source.Driver interface implementation.

func (*PartialDriver) ReadUp

func (p *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