Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.96 KB

File metadata and controls

56 lines (44 loc) · 1.96 KB

requestmigrations
Go Reference

requestmigrations is a Golang implementation of rolling versions for REST APIs. It's a port of the Ruby implementation by ezekg. We use it in production at Convoy.

Note

This README describes v2 of requestmigrations that is currently experimental. For older versions, please check the release tags.

Built By

Sponsored by Convoy

Features

  • API Versioning with date and semver versioning support.
  • Prometheus Instrumentation to track and optimize slow transformations.
  • Type-based migration system.

Installation

 go get github.com/subomi/requestmigrations/v2

Usage

RequestMigrations introduces a type-based migration system. Instead of defining migrations per API handler, migrations are now defined per Go type.

package main

import (
	"log"

	rms "github.com/subomi/requestmigrations/v2"
)

func main() {
    rm, _ := rms.NewRequestMigration(&rms.RequestMigrationOptions{
        VersionHeader:  "X-API-Version",
        CurrentVersion: "2024-06-01",
        VersionFormat:  rms.DateFormat,
    })

    // Register all migrations, then build.
    err := rm.Register(
        rms.Migration[User]("2024-01-01", &UserV1Migration{}),
        rms.Migration[User]("2024-06-01", &UserV2Migration{}),
        rms.Migration[Address]("2024-06-01", &AddressMigration{}),
    ).Build()
    if err != nil {
        log.Fatal(err)
    }
}

Example

Check the examples directory for full examples.

License

MIT License