/
githubmirror
/
pop
Обзор
Документация
Войти
/
githubmirror
/
pop
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
migration_content.go
41 строка
884 B
Antonio Pagano
v6.0.0 (#670)
23 ноя 2021, 23:04
Не верифицирован
23 ноя 2021, 23:04
c285511
Код
Авторство
О чём код?
package pop import ( "bytes" "fmt" "io" "io/ioutil" "text/template" "github.com/gobuffalo/fizz" ) // MigrationContent returns the content of a migration. func MigrationContent(mf Migration, c *Connection, r io.Reader, usingTemplate bool) (string, error) { b, err := ioutil.ReadAll(r) if err != nil { return "", nil } content := "" if usingTemplate { t := template.Must(template.New("migration").Parse(string(b))) var bb bytes.Buffer err = t.Execute(&bb, c.Dialect.Details()) if err != nil { return "", fmt.Errorf("could not execute migration template %s: %w", mf.Path, err) } content = bb.String() } else { content = string(b) } if mf.Type == "fizz" { content, err = fizz.AString(content, c.Dialect.FizzTranslator()) if err != nil { return "", fmt.Errorf("could not fizz the migration %s: %w", mf.Path, err) } } return content, nil }