ExWechatpay.Config.Helper (ex_wechatpay v0.3.5)

View Source

配置助手模块

该模块提供了一些便捷的配置管理函数,包括配置热更新、证书管理等。

Summary

Functions

获取配置模式文档

禁用自动更新证书

获取当前配置

从环境变量加载配置

检查配置是否有效

Functions

config_docs()

@spec config_docs() :: binary()

获取配置模式文档

该函数返回配置模式的详细文档,包括每个配置项的类型、默认值、说明等。

返回值

  • docs - 配置文档(Markdown 格式)

disable_auto_update_certificates(name)

@spec disable_auto_update_certificates(atom()) :: :ok

禁用自动更新证书

参数

  • name - 客户端名称

返回值

  • :ok - 成功禁用

enable_auto_update_certificates(name, interval \\ 60000 * 60 * 24)

@spec enable_auto_update_certificates(atom(), non_neg_integer()) :: :ok

启用自动更新证书

参数

  • name - 客户端名称
  • interval - 更新间隔(毫秒,默认:1天)

返回值

  • :ok - 成功启用

get_config(name)

@spec get_config(atom()) :: keyword()

获取当前配置

参数

  • name - 客户端名称

返回值

  • config - 当前配置

load_from_env()

@spec load_from_env() :: keyword()

从环境变量加载配置

返回值

  • config - 从环境变量加载的配置

update_certificates(name)

@spec update_certificates(atom()) :: {:ok, keyword()} | {:error, term()}

更新证书

参数

  • name - 客户端名称

返回值

  • {:ok, new_config} - 更新后的配置
  • {:error, error} - 更新失败的错误信息

update_config(name, updates)

@spec update_config(
  atom(),
  keyword()
) :: {:ok, keyword()} | {:error, term()}

更新配置

参数

  • name - 客户端名称
  • updates - 要更新的配置

返回值

  • {:ok, new_config} - 更新后的配置
  • {:error, error} - 更新失败的错误信息

validate_config(config)

@spec validate_config(keyword()) :: {:ok, keyword()} | {:error, term()}

检查配置是否有效

参数

  • config - 要检查的配置

返回值

  • {:ok, validated_config} - 配置有效
  • {:error, error} - 配置无效,包含错误信息