Documentation ¶
Index ¶
Constants ¶
const ( // Major signals backward-incompatible public API changes. // This release carries no guarantee that it will be // backward compatible with preceding major versions. Major = "major" // Minor signals backward-compatible public API changes. // This release guarantees backward compatibility and // stability. Minor = "minor" // Patch signals changes that don't affect the module's // public API or its dependencies. This release // guarantees backward compatibility and // stability. Patch = "patch" )
const ( // Unknown update status (something went wrong) Unknown Status = iota // DatabaseError is returned by update when a database // connection could not be established or there was // an error processing the transaction. DatabaseError = 1 // ExecutableError is returned by update when there was // a error updating the executable from GitHub. ExecutableError = 2 // CallBackError is returned by update when there was // a error with one of the migration callbacks. CallBackError = 3 // UpToDate status is used to define when the application // is already up to date. UpToDate = 5 // Updated is the success status code returned by Update // when everything passed. Updated = 6 )
Variables ¶
var ( // ErrCallBackMismatch is returned by AddMigration when // there has been a mismatch in the amount of callbacks // passed. Each migration should have two callbacks, // one up and one down, or none at all. ErrCallBackMismatch = errors.New("both CallBackUp and CallBackDown must be set") )
var ( // ErrRepositoryURL is the error returned by Validate when // a malformed repository is used. ErrRepositoryURL = errors.New("error checking repo url") )
var ( // ErrVersionMisMatch is returned by verifyInstallation if // the new downloaded version did not output the same // version parsed to Update(). ErrVersionMisMatch = errors.New("version mismatch in updated executable") )
Functions ¶
func AddMigration ¶
AddMigration adds a migration to the update registry which will be called when Update() is run. The version and Stage must be attached to the migration.
Types ¶
type CallBackFn ¶
type CallBackFn func() error
CallBackFn is the function type when migrations are running up or down.
type Migration ¶
type Migration struct { // The main version of the migration such as "v0.0.1" Version string // The migration file, byte value of the SQL migration. SQL io.Reader // CallBackUp is a function called when the migration // is going up, this can be useful when manipulating // files and directories for the current version. CallBackUp CallBackFn // CallBackUp is a function called when the migration // is going down, this is only called if an update // failed. And must be provided if CallBackUp is // defined. CallBackDown CallBackFn // Stage defines the release stage of the migration such as // Major, Minor or Patch, Stage Stage }
Migration represents a singular migration for a single version.
func GetMigration ¶
GetMigration Retrieves a migration from the registry by looking up the version. An error will be returned on failed lookup.
type MigrationRegistry ¶ added in v0.0.2
type MigrationRegistry []*Migration
MigrationRegistry contains a slice of pointers to each migration.
func AllMigrations ¶ added in v0.0.2
func AllMigrations() MigrationRegistry
AllMigrations returns all migrations in the registry.
func (MigrationRegistry) Len ¶ added in v0.0.2
func (m MigrationRegistry) Len() int
func (MigrationRegistry) Less ¶ added in v0.0.2
func (m MigrationRegistry) Less(i, j int) bool
func (MigrationRegistry) Sort ¶ added in v0.0.2
func (m MigrationRegistry) Sort()
Sort MigrationRegistry is a type that implements the sort.Interface interface so that versions can be sorted.
func (MigrationRegistry) Swap ¶ added in v0.0.2
func (m MigrationRegistry) Swap(i, j int)
type Options ¶
type Options struct { // The URL of the GitHub Repository to obtain the // executable from. GithubURL string // The currently running version. Version string // If set to true, updates will be verified by checking the // newly downloaded executable version number using the // -version flag. Verify bool // SQL database to apply migrations, migrations will not // be run if sql.DB is nil. DB *sql.DB // contains filtered or unexported fields }
Options define the core arguments parsed to the migrator.
type Patcher ¶
type Patcher interface { Update(archive string) (Status, error) HasUpdate() (bool, error) LatestVersion() (string, error) }
Patcher describes the set of methods used for determining if the application has any updates, retrieving the latest version and running migrations.
type Stage ¶
type Stage string
Stage represents the the different version stages that can be defined in a migration such as a Patch, Minor or Major.
type Status ¶
type Status int
Status defines the status codes returned by the Update() function used for debugging any issues with updating the application.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater represents the library for updating golang executables and running migrations.
func New ¶
New returns a new Updater with the options passed. If validation failed on the options an error will be returned.
func (*Updater) HasUpdate ¶
HasUpdate determines if there is an update for the program. Returns a error if there are no releases or tags for the repo.
func (*Updater) LatestVersion ¶
LatestVersion retrieves the most up to date version of the program. Returns a error if there are no releases // or tags for the repo.