feature

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package feature provides a simple mechanism for command line tools to take and parse feature flags.

Feature flag sets are passed as a struct of booleans. Non-boolean fields are ignored during parsing.

Example
package main

import (
	"fmt"

	"github.com/scionproto/scion/private/app/feature"
)

func main() {
	var featureSet struct {
		One bool `feature:"feature_one"`
		Two bool `feature:"feature_two"`
	}
	if err := feature.Parse([]string{"feature_one"}, &featureSet); err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", featureSet)
}
Output:

{One:true Two:false}
Example (NotSupported)
package main

import (
	"fmt"

	"github.com/scionproto/scion/private/app/feature"
)

func main() {
	var featureSet struct {
		One bool `feature:"named"`
	}
	err := feature.Parse([]string{"one"}, &featureSet)
	fmt.Println(err.Error())
}
Output:

feature not supported {feature=one}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Features

func Features(featureSet interface{}) []string

Features lists the supported features.

func Parse

func Parse(input []string, featureSet interface{}) error

Parse parses the features from the input into the feature set. The provided feature set should be a pointer to a struct. All boolean fields on that struct are discovered as feature flags. Non-boolean fields are ignored.

func String

func String(featureSet interface{}, sep string) string

String returns the features as a sorted list separated by the provided separator.

Types

type Default

type Default struct {
	HeaderLegacy bool `feature:"header_legacy"`
}

Default describes the default feature set.

func ParseDefault

func ParseDefault(input []string) (Default, error)

ParseDefault parses the default features from input.

Jump to

Keyboard shortcuts

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