github.com/bishtawi/migrate/v4@v4.8.11/source/httpfs/README.md (about) 1 # httpfs 2 3 ## Usage 4 5 This package could be used to create new migration source drivers that uses 6 `http.FileSystem` to read migration files. 7 8 Struct `httpfs.PartialDriver` partly implements the `source.Driver` interface. It has all 9 the methods except for `Open()`. Embedding this struct and adding `Open()` method 10 allows users of this package to create new migration sources. Example: 11 12 ```go 13 struct mydriver { 14 httpfs.PartialDriver 15 } 16 17 func (d *mydriver) Open(url string) (source.Driver, error) { 18 var fs http.FileSystem 19 var path string 20 var ds mydriver 21 22 // acquire fs and path from url 23 // set-up ds if necessary 24 25 if err := ds.Init(fs, path); err != nil { 26 return nil, err 27 } 28 return &ds, nil 29 } 30 ``` 31 32 This package also provides a simple `source.Driver` implementation that works 33 with `http.FileSystem` provided by the user of this package. It is created with 34 `httpfs.New()` call. 35 36 Example of using `http.Dir()` to read migrations from `sql` directory: 37 38 ```go 39 src, err := httpfs.New(http.Dir("sql") 40 if err != nil { 41 // do something 42 } 43 m, err := migrate.NewWithSourceInstance("httpfs", src, "database://url") 44 if err != nil { 45 // do something 46 } 47 err = m.Up() 48 ... 49 ```