2018-06-12 16:32:58 +08:00
|
|
|
# go_bindata
|
2017-02-07 22:01:29 -08:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-21 13:29:13 -07:00
|
|
|
### Read bindata with NewWithSourceInstance
|
2017-02-07 22:01:29 -08:00
|
|
|
|
2017-04-21 13:29:13 -07:00
|
|
|
```shell
|
|
|
|
go get -u github.com/jteeuwen/go-bindata/...
|
|
|
|
cd examples/migrations && go-bindata -pkg migrations .
|
2017-02-07 22:01:29 -08:00
|
|
|
```
|
|
|
|
|
2017-04-21 13:29:13 -07:00
|
|
|
```go
|
2017-02-07 22:01:29 -08:00
|
|
|
import (
|
2018-01-19 14:59:27 -08:00
|
|
|
"github.com/golang-migrate/migrate"
|
2018-06-12 16:32:58 +08:00
|
|
|
"github.com/golang-migrate/migrate/source/go_bindata"
|
|
|
|
"github.com/golang-migrate/migrate/source/go_bindata/examples/migrations"
|
2017-02-07 22:01:29 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-04-21 13:29:13 -07:00
|
|
|
// wrap assets into Resource
|
2017-02-07 22:59:12 -08:00
|
|
|
s := bindata.Resource(migrations.AssetNames(),
|
2017-02-07 22:01:29 -08:00
|
|
|
func(name string) ([]byte, error) {
|
|
|
|
return migrations.Asset(name)
|
|
|
|
})
|
2017-07-03 15:29:15 +02:00
|
|
|
|
2017-07-03 15:45:57 +02:00
|
|
|
d, err := bindata.WithInstance(s)
|
2017-07-03 15:29:15 +02:00
|
|
|
m, err := migrate.NewWithSourceInstance("go-bindata", d, "database://foobar")
|
2017-02-07 22:01:29 -08:00
|
|
|
m.Up() // run your migrations and handle the errors above of course
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-04-21 13:29:13 -07:00
|
|
|
### Read bindata with URL (todo)
|
2017-02-07 22:01:29 -08:00
|
|
|
|
2018-06-12 16:32:58 +08:00
|
|
|
This will restore the assets in a tmp directory and then
|
2017-04-21 13:29:13 -07:00
|
|
|
proxy to source/file. go-bindata must be in your `$PATH`.
|
2017-02-07 22:01:29 -08:00
|
|
|
|
2017-04-21 13:29:13 -07:00
|
|
|
```
|
2018-06-12 16:32:58 +08:00
|
|
|
migrate -source go-bindata://examples/migrations/bindata.go
|
2017-04-21 13:29:13 -07:00
|
|
|
```
|
2017-02-07 22:01:29 -08:00
|
|
|
|
|
|
|
|