config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config 提供按模块划分的明文 JSON 配置存储。

每个模块对应目录下的一个 <name>.json 文件。写入采用"临时文件 + rename"保证原子性, 文件权限为 0600,目录权限为 0700。配置保持明文,便于用户审计、备份和纳入 git。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store 是配置目录的句柄,可被多个模块并发使用。

func Open

func Open(dir string) (*Store, error)

Open 打开(必要时创建)配置目录。

func (*Store) Dir

func (s *Store) Dir() string

Dir 返回配置目录路径。

func (*Store) Load

func (s *Store) Load(name string, v any) (bool, error)

Load 读取配置到 v。文件不存在时返回 (false, nil),v 保持调用方设置的默认值。

func (*Store) Save

func (s *Store) Save(name string, v any) error

Save 将 v 以缩进 JSON 原子写入。

func (*Store) WriteRaw added in v0.2.0

func (s *Store) WriteRaw(name string, data []byte) error

WriteRaw 原子写入已序列化的配置内容(用于从备份恢复)。

Jump to

Keyboard shortcuts

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