internal

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-07 23:55:15 * @FilePath: \go-config\internal\common.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallAfterLoad

func CallAfterLoad(cfg interface{}) error

CallAfterLoad 安全调用 AfterLoad 钩子

func CallBeforeLoad

func CallBeforeLoad(cfg interface{}) error

CallBeforeLoad 安全调用 BeforeLoad 钩子

func ExportConfigToJSON

func ExportConfigToJSON(config Configurable) (string, error)

ExportConfigToJSON 导出Configurable对象为JSON

func ExportConfigToYAML

func ExportConfigToYAML(config Configurable) (string, error)

ExportConfigToYAML 导出Configurable对象为YAML

func ExportToJSON

func ExportToJSON(config interface{}) (string, error)

ExportToJSON 通用JSON导出函数

func ExportToYAML

func ExportToYAML(config interface{}) (string, error)

ExportToYAML 通用YAML导出函数

func GenerateJSONFromDefault

func GenerateJSONFromDefault(defaultFunc func() interface{}) (string, error)

GenerateJSONFromDefault 从默认配置生成JSON

func GenerateYAMLFromDefault

func GenerateYAMLFromDefault(defaultFunc func() interface{}) (string, error)

GenerateYAMLFromDefault 从默认配置生成YAML

func LockFunc

func LockFunc(fn func())

LockFunc 是一个公共方法,用于锁定和解锁

func ValidateExtra

func ValidateExtra(extraFunc func() error) error

验证额外函数

func ValidateStruct

func ValidateStruct(c interface{}) error

Validate 方法,通用验证

Types

type Configurable

type Configurable interface {
	Get() interface{}
	Set(data interface{})
	Clone() Configurable
	Validate() error
}

Configurable 接口定义了配置的基本行为

type Exportable

type Exportable interface {
	ToYAML() (string, error)
	ToJSON() (string, error)
}

Exportable 接口定义了配置的导出功能

type Hookable

type Hookable interface {
	BeforeLoad() error // 配置加载前的钩子,可用于设置默认值或预处理
	AfterLoad() error  // 配置加载后的钩子,可用于计算衍生字段或后处理
}

Hookable 接口定义了配置的钩子函数 实现此接口的配置可以在加载前后执行自定义操作

Jump to

Keyboard shortcuts

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