Documentation ¶
Overview ¶
Package bundler takes care of collecting file assets stored in different packages and putting them in a single place that might be accessible to the app or a third party static file server.
These are the kind of assets that can take care of collecting:
- migration files
- html templates
- notification templates
Index ¶
- Constants
- func ApplyMigrationsFromConfig(migrateVer string, v *viper.Viper, l logs.Logger, confPrefix string) error
- func CollectFiles(dstDir string, scanDirs []string) error
- func CollectMigrationsFromDir(path string, migrations MigrationFiles, issues []error, l logs.Logger) []error
- func CompressBundle(dstDir string) error
- func ComputeFileHash(fname string) (string, error)
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func CopyMigrationFiles(src *MigrationPair, dst *MigrationPair) error
- func DataDirs() map[string]string
- func ExecuteBundlerOperations(v *viper.Viper, l logs.Logger, confPrefix string)
- func PrepareBundle(projDir string, dstDir string, extraPkgsDirs []string, envName string) error
- func PrepareBundleDirs(dstDir string) (string, error)
- func PrepareExecutables(projDir string, dstDir string) error
- func UpdateMigrations(dstDir string, scanDirs []string, l logs.Logger) error
- func UpdateMigrationsFromConfig(v *viper.Viper, l logs.Logger, confPrefix string) error
- type MigrationFile
- type MigrationFiles
- type MigrationPair
Constants ¶
const ( // StaticDir has the directory name where the static assets // should be placed. StaticDir string = "static" // AppDir contains the root app directory, where the output // binary should be placed. AppDir string = "app" // ConfDir is the directory where the configuration for the // app will be stored. ConfDir string = "app/config" // DBMigrationsDir is the directory where database migrations // should be placed. DBMigrationsDir string = "app/dbmigrations" // AppDataDir is the directory where additional files for the // app must be placed (the ones that won't be directly served // by any other app). AppDataDir string = "app/data" // AppDataHTMLTemplates is the directory where the html templates // should be placed. AppDataHTMLTemplates string = "app/data/html_templates" // AppDataNotificationTemplates is the directory for the email // notification templates. AppDataNotificationTemplates string = "app/data/notifications/templates" )
const ( // KeyBundlerCollectMigrations is the config key for a boolean value that enables // collecting the database migration files. KeyBundlerCollectMigrations = "bundler.migrations.collect" // KeyBundlerCollectMigrationsDstDir is the config key for a string value that // tells the bundler where to place the collected migrations. KeyBundlerCollectMigrationsDstDir = "bundler.migrations.dst" // KeyBundlerCollectMigrationsScanDirs is the config key for migrations source dir. KeyBundlerCollectMigrationsScanDirs = "bundler.migrations.scan" // KeyBundlerMigrate is the config key for knowing if migrations should be applied. KeyBundlerMigrate = "bundler.migrations.migrate" // KeyBundlerPackDstDir is the config key for knowing where to place the files // to be packed with the bundler. KeyBundlerPackDstDir = "bundler.pack.dst" // KeyBundlerPackExtraDirs is the config key for knowing from where the files are // picked to be packed with the bundler. KeyBundlerPackExtraDirs = "bundler.pack.srcs" // KeyBundlerPackVariant defines the variant of the config to be put inside the bundle KeyBundlerPackVariant = "bundler.pack.variant" )
Variables ¶
This section is empty.
Functions ¶
func ApplyMigrationsFromConfig ¶
func ApplyMigrationsFromConfig(migrateVer string, v *viper.Viper, l logs.Logger, confPrefix string) error
ApplyMigrationsFromConfig reads the migrations firectory from config and applies them.
func CollectFiles ¶
CollectFiles searches for files that must be collected in diferent directories and copies them in the bundle
func CollectMigrationsFromDir ¶
func CollectMigrationsFromDir(path string, migrations MigrationFiles, issues []error, l logs.Logger) []error
CollectMigrationsFromDir scans a single direcotry
func CompressBundle ¶
CompressBundle uses a call to exec.Command to run the `tar` utility to compress the bundle.
func ComputeFileHash ¶
ComputeFileHash computes a hash for the content of a file
func CopyDir ¶
CopyDir copies one dir from source to dest ignoring symlinks, and setting a default mode
func CopyMigrationFiles ¶
func CopyMigrationFiles(src *MigrationPair, dst *MigrationPair) error
CopyMigrationFiles copies ap pair of migration files from one dir to another
func DataDirs ¶
DataDirs creates a map that returns pairs of "data target dir" to the "source data dir".
func ExecuteBundlerOperations ¶
ExecuteBundlerOperations parses the command line and environment to find operations that the bundler should execute: collect migrations, collect static files, run migrations, etc.. This function is a helper to be able to run those operations from the same server executable file.
func PrepareBundle ¶
PrepareBundle collects all static files, data files to be used by the executable, and config file.
func PrepareBundleDirs ¶
PrepareBundleDirs completely deletes the dstDir, and creates the dir structure to populate an app bundle.
func PrepareExecutables ¶
PrepareExecutables finds directories under the `cmd` dir and tries to compile each of those packages, placing the output binary under the app directory.
func UpdateMigrations ¶
UpdateMigrations finds the existing migrations in dstDir, and checks their hashes for changes, adding the new migrations as required. UpdateMigrations changes the existing IDs for their timestamps, so migration can be executed in order.
func UpdateMigrationsFromConfig ¶
UpdateMigrationsFromConfig reads the configuration values that are set to know the directory from where to collect migrations, and the directory to put the newly found migrations, to call the UpdateMigrations function that performs the actual collection.
Types ¶
type MigrationFile ¶
type MigrationFile struct { Idx int64 // the index inside the directory Base string // the base name of the migration Suffix string // .up.sql or .down.sql FullPathFile string // the path + filename file Hash string // hash of the content }
MigrationFile contains info to match existing migration files with those coming from the sources
func ParseMigrationFile ¶
func ParseMigrationFile(path string, name string) (*MigrationFile, error)
ParseMigrationFile extracts the components of a migrations file pair
type MigrationFiles ¶
type MigrationFiles map[string]MigrationPair
MigrationFiles is a map of the base name (without the prefix Id, nor the 'up.sql' / 'down.sql' extentions) to the pair of files that compose a migration
func CollectMigrations ¶
func CollectMigrations(scanDir string, l logs.Logger) (MigrationFiles, []error)
CollectMigrations scans a directory and all its descendants looking for directories called `migrations`.
func ListExistingMigrations ¶
func ListExistingMigrations(dstDir string, l logs.Logger) (MigrationFiles, []error)
ListExistingMigrations computes the hash for the 'up' and 'down' migration files.
type MigrationPair ¶
type MigrationPair struct { Up MigrationFile Down MigrationFile }
MigrationPair contains information for a pair of 'up' and 'down' migrations.