di

package
v0.0.0-...-30b4b00 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package di 依赖注入管理

用法:

  • main.go: di.Init()
  • controller: repo := di.Default(); user, _ := repo.User.GetByID(id)

测试:

di.SetDefault(&di.Manager{User: mockUserRepo})
defer di.ResetDefault()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() error

Init 初始化全局 Repository 管理器(仅执行一次) 应在 main.go 中调用,位于 DB 初始化之后

func MustChannel

func MustChannel() repository.ChannelRepository

MustChannel 返回 ChannelRepository,若为空则 panic

func MustSkill

func MustSkill() repository.SkillRepository

MustSkill 返回 SkillRepository,若为空则 panic

func MustToken

func MustToken() repository.TokenRepository

MustToken 返回 TokenRepository,若为空则 panic

func MustUser

func MustUser() repository.UserRepository

MustUser 返回 UserRepository,若为空则 panic

func ResetDefault

func ResetDefault()

ResetDefault 重置全局管理器为默认值

func SetDefault

func SetDefault(mgr *Manager)

SetDefault 设置全局管理器(主要用于测试 mock)

Types

type Manager

type Manager struct {
	User    repository.UserRepository
	Channel repository.ChannelRepository
	Token   repository.TokenRepository
	// Skill Agent Marketplace 技能目录仓库
	Skill repository.SkillRepository
}

Manager 全局 Repository 管理器

func Default

func Default() *Manager

Default 返回全局 Repository 管理器 调用前必须已执行 Init()

Jump to

Keyboard shortcuts

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