Documentation ¶
Index ¶
- Variables
- func Newmigrator(from, to *Version, avs []*Version, migrations MigrationStore) (*migrator, error)
- type GetUserVersionFunc
- type Migration
- type MigrationStore
- type Migrations
- type RequestMigration
- func (rm *RequestMigration) Migrate(r *http.Request, handler string) (error, *response, rollbackFn)
- func (rm *RequestMigration) RegisterMetrics(reg *prometheus.Registry)
- func (rm *RequestMigration) RegisterMigrations(migrations MigrationStore) error
- func (rm *RequestMigration) WriteVersionHeader() func(next http.Handler) http.Handler
- type RequestMigrationOptions
- type Version
- type VersionFormat
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Newmigrator ¶ added in v0.3.0
func Newmigrator(from, to *Version, avs []*Version, migrations MigrationStore) (*migrator, error)
Types ¶
type GetUserVersionFunc ¶ added in v0.3.0
type Migration ¶
Migration is the core interface each transformation in every version needs to implement. It includes two predicate functions and two transformation functions.
type MigrationStore ¶ added in v0.4.0
type MigrationStore map[string]Migrations
migrations := Migrations{ "2023-02-28": []Migration{ Migration{}, Migration{}, }, }
type Migrations ¶
type Migrations []Migration
Migrations is an array of migrations declared by each handler.
type RequestMigration ¶
type RequestMigration struct {
// contains filtered or unexported fields
}
RequestMigration is the exported type responsible for handling request migrations.
func NewRequestMigration ¶
func NewRequestMigration(opts *RequestMigrationOptions) (*RequestMigration, error)
func (*RequestMigration) Migrate ¶ added in v0.5.0
func (rm *RequestMigration) Migrate(r *http.Request, handler string) (error, *response, rollbackFn)
Migrate is the core API for apply transformations to your handlers. It should be called at the start of your handler to transform the body attached to your request before further processing. To transform the response as well, you need to use the rollback and res function to roll changes back and set the handler response respectively.
func (*RequestMigration) RegisterMetrics ¶ added in v0.3.0
func (rm *RequestMigration) RegisterMetrics(reg *prometheus.Registry)
func (*RequestMigration) RegisterMigrations ¶
func (rm *RequestMigration) RegisterMigrations(migrations MigrationStore) error
func (*RequestMigration) WriteVersionHeader ¶ added in v0.6.0
func (rm *RequestMigration) WriteVersionHeader() func(next http.Handler) http.Handler
type RequestMigrationOptions ¶
type RequestMigrationOptions struct { // VersionHeader refers to the header value used to retrieve the request's // version. If VersionHeader is empty, we call the GetUserVersionFunc to // retrive the user's version. VersionHeader string // CurrentVersion refers to the API's most recent version. This value should // map to the most recent version in the Migrations slice. CurrentVersion string // GetUserHeaderFunc is a function to retrieve the user's version. This is useful // where the user has a persistent version that necessarily being available in the // request. GetUserVersionFunc GetUserVersionFunc // VersionFormat is used to specify the versioning format. The two supported types // are DateFormat and SemverFormat. VersionFormat VersionFormat }
RequestMigrationOptions is used to configure the RequestMigration type.
type Version ¶
type Version struct { Format VersionFormat Value interface{} }
type VersionFormat ¶
type VersionFormat string
const ( SemverFormat VersionFormat = "semver" DateFormat VersionFormat = "date" )