flag

package
v2.331.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package flag provides helpers for defining and parsing command-line flags in go-service.

This package is a small wrapper around the standard library `flag` package that standardizes a few flag conventions used across go-service, especially configuration source selection.

Configuration input flag (-i)

Many go-service applications accept an "-i" flag that selects where configuration should be loaded from. The conventional value format is:

"kind:location"

Common examples:

  • "file:/path/to/config.yaml" to read configuration from a file (decoder selected by extension)
  • "env:MY_CONFIG" to read configuration from an environment variable (typically "<ext>:<base64-content>")

The `FlagSet` type in this package supports installing this convention via `(*FlagSet).AddInput` and retrieving it via `(*FlagSet).GetInput`. The config subsystem (`config.NewDecoder`) consumes this value to route to the appropriate decoder.

Start with `NewFlagSet`, `FlagSet.AddInput`, and `FlagSet.GetInput`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagSet

type FlagSet struct {
	*flag.FlagSet
	// contains filtered or unexported fields
}

FlagSet represents a set of defined flags.

It wraps flag.FlagSet and provides optional support for the conventional go-service configuration input flag ("-i") used by the config subsystem to route decoding.

This type is intentionally minimal: you can still use the embedded *flag.FlagSet to define and parse arbitrary flags.

func NewFlagSet

func NewFlagSet(name string) *FlagSet

NewFlagSet creates a new FlagSet with the given name.

The returned FlagSet wraps the standard library flag.FlagSet and uses flag.ContinueOnError so callers can handle parse errors explicitly (instead of terminating the process).

func (*FlagSet) AddInput

func (f *FlagSet) AddInput(value string)

AddInput adds the conventional configuration input flag ("-i") to the flag set.

The value is treated as an opaque "kind:location" string that the config package interprets. Common examples include:

  • "file:/path/to/config.yaml" (decode kind inferred from file extension)
  • "env:MY_CONFIG" (read config payload from environment variable MY_CONFIG)

The provided value is used as the default.

func (*FlagSet) GetInput

func (f *FlagSet) GetInput() string

GetInput returns the configured input flag ("-i") value.

This method is nil-safe with respect to AddInput: if AddInput was not called, GetInput returns an empty string. This allows callers to depend on GetInput unconditionally.

Jump to

Keyboard shortcuts

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