config

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Overview

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	DefaultOutput  = "json"
	DefaultTimeout = 30 * time.Second
)

Variables

View Source
var (
	ErrNamespaceNameRequired = errors.New("namespace name is required")
	ErrNamespaceNotFound     = errors.New("namespace not found")
	ErrNoCurrentNamespace    = errors.New("current namespace is not configured")
)

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath 返回默认 CLI 配置文件路径。 DefaultPath returns the default CLI configuration file path.

Types

type File

type File struct {
	CurrentNamespace string               `yaml:"current_namespace,omitempty"`
	Namespaces       map[string]Namespace `yaml:"namespaces,omitempty"`
}

File 表示 STX CLI 的本地配置文件。 File represents the local STX CLI configuration file.

type NamedNamespace

type NamedNamespace struct {
	Name    string
	Current bool
	Server  string
}

NamedNamespace 是带名称和当前状态的命名空间视图。 NamedNamespace is a namespace view with its name and current status.

type Namespace

type Namespace struct {
	Server         string `yaml:"server,omitempty"`
	Token          string `yaml:"token,omitempty"`
	TokenExpiresAt string `yaml:"token_expires_at,omitempty"`
	Output         string `yaml:"output,omitempty"`
	Timeout        string `yaml:"timeout,omitempty"`
}

Namespace 保存一个远端 STX 服务及其本地凭据。 Namespace stores one remote STX server and its local credentials.

type Overrides

type Overrides struct {
	Namespace string
	Server    string
	Token     string
	Output    string
	Timeout   string
}

Overrides 表示高于配置文件优先级的命令参数。 Overrides represents command arguments that take precedence over the config file.

type Resolved

type Resolved struct {
	Name           string
	Server         string
	Token          string
	TokenExpiresAt string
	Output         string
	Timeout        time.Duration
}

Resolved 表示应用命令参数、环境变量和默认值后的有效配置。 Resolved represents effective configuration after command arguments, environment variables, and defaults are applied.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 管理一个 CLI 配置文件。 Store manages one CLI configuration file.

func NewDefaultStore

func NewDefaultStore() (*Store, error)

NewDefaultStore 创建默认路径的配置存储。 NewDefaultStore creates a configuration store at the default path.

func NewStore

func NewStore(path string) *Store

NewStore 创建指定路径的配置存储。 NewStore creates a configuration store at the specified path.

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete 删除命名空间;删除当前项后选择名称排序后的第一项。 Delete removes a namespace and selects the first sorted remaining name when deleting the current one.

func (*Store) Get

func (s *Store) Get(name string) (string, Namespace, error)

Get 返回指定命名空间;名称为空时使用当前命名空间。 Get returns a named namespace, using the current namespace when name is empty.

func (*Store) List

func (s *Store) List() ([]NamedNamespace, error)

List 返回按名称排序且不包含令牌的命名空间元数据。 List returns namespace metadata sorted by name without tokens.

func (*Store) Load

func (s *Store) Load() (*File, error)

Load 读取配置;文件不存在时返回空配置。 Load reads configuration and returns an empty configuration when the file does not exist.

func (*Store) Path

func (s *Store) Path() string

Path 返回配置文件路径。 Path returns the configuration file path.

func (*Store) Resolve

func (s *Store) Resolve(overrides Overrides) (Resolved, error)

Resolve 按命令参数、环境变量、当前命名空间和默认值解析有效配置。 Resolve applies command arguments, environment variables, current namespace values, and defaults in priority order.

func (*Store) Save

func (s *Store) Save(file *File) error

Save 以受限权限原子保存配置。 Save atomically persists configuration with restricted permissions.

func (*Store) Upsert

func (s *Store) Upsert(name string, namespace Namespace, makeCurrent bool) error

Upsert 新增或更新命名空间,并可将其设为当前命名空间。 Upsert creates or updates a namespace and can make it current.

func (*Store) Use

func (s *Store) Use(name string) error

Use 将已存在的命名空间设为当前命名空间。 Use selects an existing namespace as current.

Jump to

Keyboard shortcuts

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