toggle

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

OAPI-Gin-API-Toggle

Overview

OAPI-Gin-API-Toggle is a Go package that provides middleware for managing feature flags in a Gin-based web application. It utilizes OpenAPI specifications extensions to determine which routes are enabled based on the provided feature flags.

Installation

To install the package, use the following command:

go get github.com/SBhanushali/oapi-gin-api-toggle

Usage

  1. Import the package:
import "github.com/SBhanushali/oapi-gin-api-toggle"
  1. Example Usage:

package main

import (
	"github.com/SBhanushali/oapi-gin-api-toggle"
	"github.com/gin-gonic/gin"
)

func main() {
  router := gin.Default()

  swagger, _ := spec.GetSwagger() // Get the swagger spec from oapi-codegen generated code

  config := toggle.Config{
    ExtensionName: "x-feature-flag",
    FeatureFlags: map[string]bool{
      "feature1": true,
      "feature2": false,
    },
  }

  router.Use(toggle.New(swagger, config))

  router.Run(":8080")
}

Full example can be found here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(swagger *openapi3.T, config Config) gin.HandlerFunc

Types

type Config

type Config struct {
	// ExtensionName is the name of the extension starting with x-*. This is the name of the extension that will be used to check for feature flags.
	ExtensionName string
	// FeatureFlags is a map of feature flag assigned to extension name and their enabled status
	FeatureFlags map[string]bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL