infra

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package infra 提供基础设施(MongoDB / Redis)的统一初始化入口。 消费服务在启动阶段调用 Init 一次性初始化并持有,或通过 wire 装配 InfraSet 注入。

Index

Constants

This section is empty.

Variables

InfraSet wire provider 集合:复用 db.MongoSet(MongoDB)与 extend/redis.NewClient(Redis)。

Functions

This section is empty.

Types

type Infra

type Infra struct {
	MongoClient *mongo.Client
	MongoDB     *mongo.Database
	Redis       goredis.UniversalClient
}

Infra 统一持有已初始化的基础设施;未启用/未配置的组件为 nil。

func Init

func Init() (*Infra, error)

Init 读取 gobase 配置,初始化已启用的组件:

  • MongoDB:配置存在 database.mongodb.uri 时连接(复用 db.NewClient/NewDatabase);
  • Redis:redis.enable=true 时连接(复用 extend/redis.NewClient,自动识别 standalone/sentinel/cluster)。

未启用/未配置的组件保持 nil,不建立默认地址连接。调用前需先加载配置(config.LoadConfig / gobasecfg.Init)。

func NewInfra

func NewInfra(mc *mongo.Client, mdb *mongo.Database, rds goredis.UniversalClient) *Infra

NewInfra wire provider:组合已初始化的 MongoDB client/database 与 Redis client。

func (*Infra) Close

func (i *Infra) Close() error

Close 关闭底层连接(幂等;nil 组件跳过)。返回首个非 nil 错误。

Jump to

Keyboard shortcuts

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