config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config contains profile and configuration loading logic.

Index

Constants

View Source
const (
	// DefaultProfileName is used when no profile is selected.
	DefaultProfileName = "default"

	// EnvConfigDir overrides the default configuration directory.
	EnvConfigDir = "MOCKLET_CONFIG_DIR"
	// EnvProfile chooses the active profile.
	EnvProfile = "MOCKLET_PROFILE"
	// EnvAPIBaseURL overrides the management API base URL.
	EnvAPIBaseURL = "MOCKLET_API_BASE_URL"
	// EnvAuthBaseURL overrides the auth API base URL.
	EnvAuthBaseURL = "MOCKLET_AUTH_BASE_URL"
	// EnvOutput overrides output mode.
	EnvOutput = "MOCKLET_OUTPUT"
	// EnvQuiet enables quiet output mode.
	EnvQuiet = "MOCKLET_QUIET"
	// EnvVerbose enables verbose output mode.
	EnvVerbose = "MOCKLET_VERBOSE"
	// EnvNoColor disables colorized output.
	EnvNoColor = "MOCKLET_NO_COLOR"
	// EnvNonInteractive disables interactive prompts.
	EnvNonInteractive = "MOCKLET_NON_INTERACTIVE"
	// EnvRequestID sets a static request-id header value.
	EnvRequestID = "MOCKLET_REQUEST_ID"
	// EnvTimeout sets request timeout (for example "30s").
	EnvTimeout = "MOCKLET_TIMEOUT"
)

Variables

View Source
var (
	// ErrProfileNotFound indicates profile file does not exist.
	ErrProfileNotFound = errors.New("profile not found")
)

Functions

func DefaultConfigDir

func DefaultConfigDir() string

DefaultConfigDir returns the config directory path.

Types

type FileProfileStore

type FileProfileStore struct {
	ConfigDir string
}

FileProfileStore loads profiles from JSON files.

func NewFileProfileStore

func NewFileProfileStore(configDir string) FileProfileStore

NewFileProfileStore creates a file-backed profile store.

func (FileProfileStore) Load

func (s FileProfileStore) Load(name string) (Profile, error)

Load returns profile values for the given name.

type FlagInputs

type FlagInputs struct {
	Profile        *string
	APIBaseURL     *string
	AuthBaseURL    *string
	Output         *string
	Quiet          *bool
	Verbose        *bool
	NoColor        *bool
	NonInteractive *bool
	RequestID      *string
	Timeout        *time.Duration
}

FlagInputs contains explicitly set CLI flag values. Nil means "flag was not set", so lower precedence values remain eligible.

type OutputMode

type OutputMode string

OutputMode is the public output rendering mode.

const (
	OutputHuman OutputMode = "human"
	OutputJSON  OutputMode = "json"
	OutputTable OutputMode = "table"
)

func (OutputMode) Valid

func (m OutputMode) Valid() bool

Valid reports whether output mode is supported.

type Profile

type Profile struct {
	APIBaseURL     string `json:"api_base_url,omitempty"`
	AuthBaseURL    string `json:"auth_base_url,omitempty"`
	Output         string `json:"output,omitempty"`
	Quiet          *bool  `json:"quiet,omitempty"`
	Verbose        *bool  `json:"verbose,omitempty"`
	NoColor        *bool  `json:"no_color,omitempty"`
	NonInteractive *bool  `json:"non_interactive,omitempty"`
	RequestID      string `json:"request_id,omitempty"`
	Timeout        string `json:"timeout,omitempty"`
}

Profile stores user profile values loaded from disk.

type ProfileStore

type ProfileStore interface {
	Load(name string) (Profile, error)
}

ProfileStore loads profile definitions by name.

type ResolvedConfig

type ResolvedConfig struct {
	ProfileName    string
	APIBaseURL     string
	AuthBaseURL    string
	Output         OutputMode
	Quiet          bool
	Verbose        bool
	NoColor        bool
	NonInteractive bool
	RequestID      string
	Timeout        time.Duration
	ConfigDir      string
}

ResolvedConfig is the final runtime configuration after precedence resolution.

type Resolver

type Resolver struct {
	LookupEnv    func(string) (string, bool)
	ProfileStore ProfileStore
	Defaults     ResolvedConfig
	ConfigDir    string
}

Resolver resolves runtime config from defaults, profile, env and flags.

func NewResolver

func NewResolver(configDir string, store ProfileStore) Resolver

NewResolver builds a resolver with production defaults.

func (Resolver) Resolve

func (r Resolver) Resolve(flags FlagInputs) (ResolvedConfig, error)

Resolve evaluates precedence: flags > env > profile > defaults.

Jump to

Keyboard shortcuts

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