Documentation
¶
Overview ¶
Package container provides runtime dependency injection container for gorp framework. This file provides strongly typed access helpers for app-service style bindings. Reduces repetitive container type assertions in business and bootstrap code.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件为 app-service 风格绑定提供强类型访问 helper。 减少业务代码和 bootstrap 代码中重复的容器类型断言。
Package container provides runtime dependency injection container for gorp framework. This file exposes security-related convenience helpers for JWT capability access. Keeps common auth service lookup compact for handlers, middleware, bootstrap hooks.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件暴露聚焦安全能力的便捷 helper。 让 handler、middleware 和 bootstrap hook 获取 JWT 能力时保持简洁。
Package container provides runtime dependency injection container for gorp framework. This file exposes typed config access helpers on top of runtime container. Keeps config capability lookup consistent across bootstrap and application code.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件在运行时容器之上暴露强类型配置访问 helper。 让 bootstrap 与 application 代码获取配置能力时保持一致。
Package container provides runtime dependency injection container for gorp framework. Manages direct bindings, deferred providers, singleton lifecycle, and provider boot order. Serves as central assembly point for providers used by bootstrap and application startup.
容器包提供 gorp 框架的运行时依赖注入容器实现。 管理直接绑定、延迟 provider、单例生命周期和 provider 启动顺序。 作为 bootstrap 与 application 启动阶段装配 provider 的核心承载点。
Package container provides runtime dependency injection container for gorp framework. This file manages the process-wide default container used by facade packages. Keeps default container reads and writes concurrency-safe with noop fallback.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件管理 facade 包使用的进程级默认容器。 保证默认容器的读写具备并发安全,提供 noop 回退。
Package container provides runtime dependency injection container for gorp framework. This file offers provider introspection and diagnostics helper methods. Supports CLI or tooling queries without polluting core container contract.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件提供 provider 维度的辅助查询和诊断能力。 支持 CLI 或工具侧查询,而不污染核心运行时容器契约。
Package container provides runtime dependency injection container for gorp framework. This file exposes strongly typed helper accessors for common capabilities. All helpers delegate to the generic MakeWith[T] / MustMakeWith[T] functions, eliminating bare type assertions and providing type-mismatch error messages.
容器包提供 gorp 框架的运行时依赖注入容器实现。 本文件在通用运行时容器之上暴露强类型辅助访问入口。 所有 helper 委托给泛型 MakeWith[T] / MustMakeWith[T], 消除裸类型断言,并在类型不匹配时提供可读错误信息。
Index ¶
- Variables
- func Default() runtimecontract.Container
- func GetCache(c runtimecontract.Container) (datacontract.Cache, error)
- func GetCacheOrPanic(c runtimecontract.Container) datacontract.Cache
- func GetConfigOrPanic(c runtimecontract.Container) datacontract.Config
- func GetCron(c runtimecontract.Container) (runtimecontract.Cron, error)
- func GetCronOrPanic(c runtimecontract.Container) runtimecontract.Cron
- func GetDB(c runtimecontract.Container) (*gormdb.DB, *sqlx.DB, error)
- func GetDBOrPanic(c runtimecontract.Container) (*gormdb.DB, *sqlx.DB)
- func GetDBRuntime(c runtimecontract.Container) (any, error)
- func GetDistributedLock(c runtimecontract.Container) (datacontract.DistributedLock, error)
- func GetDistributedLockOrPanic(c runtimecontract.Container) datacontract.DistributedLock
- func GetGRPCConnFactory(c runtimecontract.Container) (transportcontract.GRPCConnFactory, error)
- func GetGRPCConnFactoryOrPanic(c runtimecontract.Container) transportcontract.GRPCConnFactory
- func GetGRPCServerRegistrar(c runtimecontract.Container) (transportcontract.GRPCServerRegistrar, error)
- func GetGRPCServerRegistrarOrPanic(c runtimecontract.Container) transportcontract.GRPCServerRegistrar
- func GetGorm(c runtimecontract.Container) (*gormdb.DB, error)
- func GetGormOrPanic(c runtimecontract.Container) *gormdb.DB
- func GetHTTP(c runtimecontract.Container) (transportcontract.HTTP, error)
- func GetHTTPOrPanic(c runtimecontract.Container) transportcontract.HTTP
- func GetHost(c runtimecontract.Container) (runtimecontract.Host, error)
- func GetJWT(c runtimecontract.Container) (securitycontract.JWTService, error)
- func GetJWTOrPanic(c runtimecontract.Container) securitycontract.JWTService
- func GetLogger(c runtimecontract.Container) (observabilitycontract.Logger, error)
- func GetLoggerOrPanic(c runtimecontract.Container) observabilitycontract.Logger
- func GetMessagePublisher(c runtimecontract.Container) (integrationcontract.MessagePublisher, error)
- func GetMessagePublisherOrPanic(c runtimecontract.Container) integrationcontract.MessagePublisher
- func GetMessageSubscriber(c runtimecontract.Container) (integrationcontract.MessageSubscriber, error)
- func GetMessageSubscriberOrPanic(c runtimecontract.Container) integrationcontract.MessageSubscriber
- func GetMiddlewareRegistry(c runtimecontract.Container) (transportcontract.MiddlewareRegistry, error)
- func GetMiddlewareRegistryOrPanic(c runtimecontract.Container) transportcontract.MiddlewareRegistry
- func GetRedis(c runtimecontract.Container) (datacontract.Redis, error)
- func GetRetry(c runtimecontract.Container) (resiliencecontract.Retry, error)
- func GetRetryOrPanic(c runtimecontract.Container) resiliencecontract.Retry
- func GetRouter(c runtimecontract.Container) (transportcontract.Router, error)
- func GetRouterOrPanic(c runtimecontract.Container) transportcontract.Router
- func GetSQLX(c runtimecontract.Container) (*sqlx.DB, error)
- func GetSQLXOrPanic(c runtimecontract.Container) *sqlx.DB
- func GetServiceAuthenticator(c runtimecontract.Container) (securitycontract.ServiceAuthenticator, error)
- func GetServiceAuthenticatorOrPanic(c runtimecontract.Container) securitycontract.ServiceAuthenticator
- func GetServiceTokenIssuer(c runtimecontract.Container) (securitycontract.ServiceTokenIssuer, error)
- func GetServiceTokenIssuerOrPanic(c runtimecontract.Container) securitycontract.ServiceTokenIssuer
- func GetValidator(c runtimecontract.Container) (datacontract.Validator, error)
- func GetValidatorOrPanic(c runtimecontract.Container) datacontract.Validator
- func GetWebSocketServer(c runtimecontract.Container) (transportcontract.WebSocketServer, error)
- func GetWebSocketServerOrPanic(c runtimecontract.Container) transportcontract.WebSocketServer
- func MakeAppService[T any](c runtimecontract.Container, key string) (T, error)
- func MakeCache(c runtimecontract.Container) (datacontract.Cache, error)
- func MakeConfig(c runtimecontract.Container) (datacontract.Config, error)
- func MakeCron(c runtimecontract.Container) (runtimecontract.Cron, error)
- func MakeDBRuntime(c runtimecontract.Container) (any, error)
- func MakeDistributedLock(c runtimecontract.Container) (datacontract.DistributedLock, error)
- func MakeGRPCConnFactory(c runtimecontract.Container) (transportcontract.GRPCConnFactory, error)
- func MakeGRPCServerRegistrar(c runtimecontract.Container) (transportcontract.GRPCServerRegistrar, error)
- func MakeGormDB(c runtimecontract.Container) (*gormdb.DB, error)
- func MakeHTTP(c runtimecontract.Container) (transportcontract.HTTP, error)
- func MakeHost(c runtimecontract.Container) (runtimecontract.Host, error)
- func MakeLogger(c runtimecontract.Container) (observabilitycontract.Logger, error)
- func MakeMessagePublisher(c runtimecontract.Container) (integrationcontract.MessagePublisher, error)
- func MakeMessageSubscriber(c runtimecontract.Container) (integrationcontract.MessageSubscriber, error)
- func MakeNamedWith[T any](c runtimecontract.Container, name, key string) (T, error)
- func MakeRedis(c runtimecontract.Container) (datacontract.Redis, error)
- func MakeRetry(c runtimecontract.Container) (resiliencecontract.Retry, error)
- func MakeRouter(c runtimecontract.Container) (transportcontract.Router, error)
- func MakeSQLX(c runtimecontract.Container) (*sqlx.DB, error)
- func MakeValidator(c runtimecontract.Container) (datacontract.Validator, error)
- func MakeWith[T any](c runtimecontract.Container, key string) (T, error)
- func MustMakeAppService[T any](c runtimecontract.Container, key string) T
- func MustMakeCache(c runtimecontract.Container) datacontract.Cache
- func MustMakeConfig(c runtimecontract.Container) datacontract.Config
- func MustMakeCron(c runtimecontract.Container) runtimecontract.Cron
- func MustMakeDB(c runtimecontract.Container) (*gormdb.DB, *sqlx.DB)
- func MustMakeDistributedLock(c runtimecontract.Container) datacontract.DistributedLock
- func MustMakeGRPCConnFactory(c runtimecontract.Container) transportcontract.GRPCConnFactory
- func MustMakeGRPCServerRegistrar(c runtimecontract.Container) transportcontract.GRPCServerRegistrar
- func MustMakeGorm(c runtimecontract.Container) *gormdb.DB
- func MustMakeGormDB(c runtimecontract.Container) *gormdb.DB
- func MustMakeHTTP(c runtimecontract.Container) transportcontract.HTTP
- func MustMakeJWT(c runtimecontract.Container) securitycontract.JWTService
- func MustMakeJWTService(c runtimecontract.Container) securitycontract.JWTService
- func MustMakeLogger(c runtimecontract.Container) observabilitycontract.Logger
- func MustMakeMessagePublisher(c runtimecontract.Container) integrationcontract.MessagePublisher
- func MustMakeMessageSubscriber(c runtimecontract.Container) integrationcontract.MessageSubscriber
- func MustMakeNamedWith[T any](c runtimecontract.Container, name, key string) T
- func MustMakeRetry(c runtimecontract.Container) resiliencecontract.Retry
- func MustMakeRouter(c runtimecontract.Container) transportcontract.Router
- func MustMakeSQLX(c runtimecontract.Container) *sqlx.DB
- func MustMakeValidator(c runtimecontract.Container) datacontract.Validator
- func MustMakeWith[T any](c runtimecontract.Container, key string) T
- func PingDBRuntime(dbAny any) error
- func Resolve(ctx context.Context) runtimecontract.Container
- func SetDefault(c runtimecontract.Container)
- type Container
- func (c *Container) Bind(key string, factory runtimecontract.Factory, singleton bool)
- func (c *Container) DebugPrint() string
- func (c *Container) Destroy() error
- func (c *Container) IsBind(key string) bool
- func (c *Container) IsBindNamed(name, key string) bool
- func (c *Container) Make(key string) (any, error)
- func (c *Container) MakeNamed(name, key string) (any, error)
- func (c *Container) MustMake(key string) any
- func (c *Container) MustMakeNamed(name, key string) any
- func (c *Container) NamedBind(name, key string, factory runtimecontract.Factory, singleton bool)
- func (c *Container) ProviderDAG() runtimecontract.ProviderDAG
- func (c *Container) ProviderNames() []string
- func (c *Container) RegisterCloser(key string, closer io.Closer)
- func (c *Container) RegisterProvider(p runtimecontract.ServiceProvider) error
- func (c *Container) RegisterProviders(providers ...runtimecontract.ServiceProvider) error
- func (c *Container) RegisteredProviders() []runtimecontract.ProviderInfo
Constants ¶
This section is empty.
Variables ¶
var ErrDefaultContainerNotSet = errors.New("container: default container has not been set, please call gorp.Run first")
ErrDefaultContainerNotSet 全局默认 Container 未设置时 Make 返回此错误。 业务代码在 gorp.Run 启动前调用 facade 会触发此错误。
Functions ¶
func Default ¶ added in v0.1.4
func Default() runtimecontract.Container
Default 返回全局默认 Container。 如果尚未设置(gorp.Run 未调用),返回 noopContainer,其 Make 返回 ErrDefaultContainerNotSet。
Default returns the process-wide default container. If not set, returns a noopContainer whose Make returns ErrDefaultContainerNotSet.
func GetCache ¶
func GetCache(c runtimecontract.Container) (datacontract.Cache, error)
GetCache resolves the cache capability from the container.
GetCache 从容器中解析缓存能力。
func GetCacheOrPanic ¶
func GetCacheOrPanic(c runtimecontract.Container) datacontract.Cache
GetCacheOrPanic resolves the cache capability and panics on failure.
GetCacheOrPanic 解析缓存能力,失败时 panic。
func GetConfigOrPanic ¶
func GetConfigOrPanic(c runtimecontract.Container) datacontract.Config
GetConfigOrPanic resolves the config capability and panics on failure.
GetConfigOrPanic 解析配置能力,失败时 panic。
func GetCron ¶
func GetCron(c runtimecontract.Container) (runtimecontract.Cron, error)
GetCron resolves the cron capability from the container.
GetCron 从容器中解析定时任务能力。
func GetCronOrPanic ¶
func GetCronOrPanic(c runtimecontract.Container) runtimecontract.Cron
GetCronOrPanic resolves the cron capability and panics on failure.
GetCronOrPanic 解析定时任务能力,失败时 panic。
func GetDB ¶
GetDB resolves both Gorm and SQLX database handles from the container.
GetDB 从容器中解析 Gorm 和 SQLX 数据库句柄。
func GetDBOrPanic ¶
GetDBOrPanic resolves both Gorm and SQLX database handles from the container. Panics if either is not available.
GetDBOrPanic 从容器中解析 Gorm 和 SQLX 数据库句柄,失败时 panic。 这两个句柄指向同一个数据库连接,业务可根据场景选择使用。
func GetDBRuntime ¶
func GetDBRuntime(c runtimecontract.Container) (any, error)
GetDBRuntime resolves the database runtime object from the container.
GetDBRuntime 从容器中解析数据库运行时对象。
func GetDistributedLock ¶
func GetDistributedLock(c runtimecontract.Container) (datacontract.DistributedLock, error)
GetDistributedLock resolves the distributed lock capability from the container.
GetDistributedLock 从容器中解析分布式锁能力。
func GetDistributedLockOrPanic ¶
func GetDistributedLockOrPanic(c runtimecontract.Container) datacontract.DistributedLock
GetDistributedLockOrPanic resolves the distributed lock capability and panics on failure.
GetDistributedLockOrPanic 解析分布式锁能力,失败时 panic。
func GetGRPCConnFactory ¶
func GetGRPCConnFactory(c runtimecontract.Container) (transportcontract.GRPCConnFactory, error)
GetGRPCConnFactory resolves the gRPC connection factory from the container.
GetGRPCConnFactory 从容器中解析 gRPC 连接工厂。
func GetGRPCConnFactoryOrPanic ¶
func GetGRPCConnFactoryOrPanic(c runtimecontract.Container) transportcontract.GRPCConnFactory
GetGRPCConnFactoryOrPanic resolves the gRPC connection factory and panics on failure.
GetGRPCConnFactoryOrPanic 解析 gRPC 连接工厂,失败时 panic。
func GetGRPCServerRegistrar ¶
func GetGRPCServerRegistrar(c runtimecontract.Container) (transportcontract.GRPCServerRegistrar, error)
GetGRPCServerRegistrar resolves the gRPC server registrar from the container.
GetGRPCServerRegistrar 从容器中解析 gRPC 服务注册器。
func GetGRPCServerRegistrarOrPanic ¶
func GetGRPCServerRegistrarOrPanic(c runtimecontract.Container) transportcontract.GRPCServerRegistrar
GetGRPCServerRegistrarOrPanic resolves the gRPC server registrar and panics on failure.
GetGRPCServerRegistrarOrPanic 解析 gRPC 服务注册器,失败时 panic。
func GetGorm ¶
func GetGorm(c runtimecontract.Container) (*gormdb.DB, error)
GetGorm resolves the Gorm database handle from the container.
GetGorm 从容器中解析 Gorm 数据库句柄。
func GetGormOrPanic ¶
func GetGormOrPanic(c runtimecontract.Container) *gormdb.DB
GetGormOrPanic resolves the Gorm database handle and panics on failure.
GetGormOrPanic 解析 Gorm 数据库句柄,失败时 panic。
func GetHTTP ¶
func GetHTTP(c runtimecontract.Container) (transportcontract.HTTP, error)
GetHTTP resolves the HTTP service from the container.
GetHTTP 从容器中解析 HTTP 服务。
func GetHTTPOrPanic ¶
func GetHTTPOrPanic(c runtimecontract.Container) transportcontract.HTTP
GetHTTPOrPanic resolves the HTTP service and panics on failure.
GetHTTPOrPanic 解析 HTTP 服务,失败时 panic。
func GetHost ¶
func GetHost(c runtimecontract.Container) (runtimecontract.Host, error)
GetHost resolves the host capability from the container.
GetHost 从容器中解析 host 能力。
func GetJWT ¶
func GetJWT(c runtimecontract.Container) (securitycontract.JWTService, error)
GetJWT resolves the JWT service from the container.
GetJWT 从容器中解析 JWT 服务。
func GetJWTOrPanic ¶
func GetJWTOrPanic(c runtimecontract.Container) securitycontract.JWTService
GetJWTOrPanic resolves the JWT service and panics on failure.
GetJWTOrPanic 解析 JWT 服务,失败时 panic。
func GetLogger ¶
func GetLogger(c runtimecontract.Container) (observabilitycontract.Logger, error)
GetLogger resolves the logger capability from the container.
GetLogger 从容器中解析日志能力。
func GetLoggerOrPanic ¶
func GetLoggerOrPanic(c runtimecontract.Container) observabilitycontract.Logger
GetLoggerOrPanic resolves the logger and panics on failure.
GetLoggerOrPanic 解析日志能力,失败时 panic。
func GetMessagePublisher ¶
func GetMessagePublisher(c runtimecontract.Container) (integrationcontract.MessagePublisher, error)
GetMessagePublisher resolves the message publisher from the container.
GetMessagePublisher 从容器中解析消息发布能力。
func GetMessagePublisherOrPanic ¶
func GetMessagePublisherOrPanic(c runtimecontract.Container) integrationcontract.MessagePublisher
GetMessagePublisherOrPanic resolves the message publisher and panics on failure.
GetMessagePublisherOrPanic 解析消息发布能力,失败时 panic。
func GetMessageSubscriber ¶
func GetMessageSubscriber(c runtimecontract.Container) (integrationcontract.MessageSubscriber, error)
GetMessageSubscriber resolves the message subscriber from the container.
GetMessageSubscriber 从容器中解析消息订阅能力。
func GetMessageSubscriberOrPanic ¶
func GetMessageSubscriberOrPanic(c runtimecontract.Container) integrationcontract.MessageSubscriber
GetMessageSubscriberOrPanic resolves the message subscriber and panics on failure.
GetMessageSubscriberOrPanic 解析消息订阅能力,失败时 panic。
func GetMiddlewareRegistry ¶
func GetMiddlewareRegistry(c runtimecontract.Container) (transportcontract.MiddlewareRegistry, error)
GetMiddlewareRegistry resolves the middleware registry from the container.
GetMiddlewareRegistry 从容器中解析中间件注册表。
func GetMiddlewareRegistryOrPanic ¶
func GetMiddlewareRegistryOrPanic(c runtimecontract.Container) transportcontract.MiddlewareRegistry
GetMiddlewareRegistryOrPanic resolves the middleware registry and panics on failure.
GetMiddlewareRegistryOrPanic 解析中间件注册表,失败时 panic。
func GetRedis ¶
func GetRedis(c runtimecontract.Container) (datacontract.Redis, error)
GetRedis resolves the Redis capability from the container.
GetRedis 从容器中解析 Redis 能力。
func GetRetry ¶
func GetRetry(c runtimecontract.Container) (resiliencecontract.Retry, error)
GetRetry resolves the retry capability from the container.
GetRetry 从容器中解析重试策略能力。
func GetRetryOrPanic ¶
func GetRetryOrPanic(c runtimecontract.Container) resiliencecontract.Retry
GetRetryOrPanic resolves the retry capability and panics on failure.
GetRetryOrPanic 解析重试策略能力,失败时 panic。
func GetRouter ¶
func GetRouter(c runtimecontract.Container) (transportcontract.Router, error)
GetRouter resolves the HTTP router facade from the container.
GetRouter 从容器中解析 HTTP 路由门面。
func GetRouterOrPanic ¶
func GetRouterOrPanic(c runtimecontract.Container) transportcontract.Router
GetRouterOrPanic resolves the HTTP router facade and panics on failure.
GetRouterOrPanic 解析 HTTP 路由门面,失败时 panic。
func GetSQLX ¶
func GetSQLX(c runtimecontract.Container) (*sqlx.DB, error)
GetSQLX resolves the SQLX database handle from the container.
GetSQLX 从容器中解析 SQLX 数据库句柄。
func GetSQLXOrPanic ¶
func GetSQLXOrPanic(c runtimecontract.Container) *sqlx.DB
GetSQLXOrPanic resolves the SQLX database handle and panics on failure.
GetSQLXOrPanic 解析 SQLX 数据库句柄,失败时 panic。
func GetServiceAuthenticator ¶
func GetServiceAuthenticator(c runtimecontract.Container) (securitycontract.ServiceAuthenticator, error)
GetServiceAuthenticator resolves the service authenticator from the container.
GetServiceAuthenticator 从容器中解析服务认证器。
func GetServiceAuthenticatorOrPanic ¶
func GetServiceAuthenticatorOrPanic(c runtimecontract.Container) securitycontract.ServiceAuthenticator
GetServiceAuthenticatorOrPanic resolves the service authenticator and panics on failure.
GetServiceAuthenticatorOrPanic 解析服务认证器,失败时 panic。
func GetServiceTokenIssuer ¶
func GetServiceTokenIssuer(c runtimecontract.Container) (securitycontract.ServiceTokenIssuer, error)
GetServiceTokenIssuer resolves the service token issuer from the container.
GetServiceTokenIssuer 从容器中解析服务令牌签发器。
func GetServiceTokenIssuerOrPanic ¶
func GetServiceTokenIssuerOrPanic(c runtimecontract.Container) securitycontract.ServiceTokenIssuer
GetServiceTokenIssuerOrPanic resolves the service token issuer and panics on failure.
GetServiceTokenIssuerOrPanic 解析服务令牌签发器,失败时 panic。
func GetValidator ¶
func GetValidator(c runtimecontract.Container) (datacontract.Validator, error)
GetValidator resolves the validator capability from the container.
GetValidator 从容器中解析参数校验能力。
func GetValidatorOrPanic ¶
func GetValidatorOrPanic(c runtimecontract.Container) datacontract.Validator
GetValidatorOrPanic resolves the validator capability and panics on failure.
GetValidatorOrPanic 解析参数校验能力,失败时 panic。
func GetWebSocketServer ¶
func GetWebSocketServer(c runtimecontract.Container) (transportcontract.WebSocketServer, error)
GetWebSocketServer resolves the WebSocket server from the container.
GetWebSocketServer 从容器中解析 WebSocket 服务器。
func GetWebSocketServerOrPanic ¶
func GetWebSocketServerOrPanic(c runtimecontract.Container) transportcontract.WebSocketServer
GetWebSocketServerOrPanic resolves the WebSocket server and panics on failure.
GetWebSocketServerOrPanic 解析 WebSocket 服务器,失败时 panic。
func MakeAppService ¶
func MakeAppService[T any](c runtimecontract.Container, key string) (T, error)
MakeAppService resolves an app service by key and casts it to the requested type.
MakeAppService 按 key 解析 app service,并转换成目标类型。
func MakeCache ¶
func MakeCache(c runtimecontract.Container) (datacontract.Cache, error)
MakeCache is an alias for GetCache.
MakeCache 是 GetCache 的别名。
func MakeConfig ¶
func MakeConfig(c runtimecontract.Container) (datacontract.Config, error)
MakeConfig resolves the config capability from the container.
MakeConfig 从容器中解析配置能力。
func MakeCron ¶
func MakeCron(c runtimecontract.Container) (runtimecontract.Cron, error)
MakeCron is an alias for GetCron.
MakeCron 是 GetCron 的别名。
func MakeDBRuntime ¶
func MakeDBRuntime(c runtimecontract.Container) (any, error)
MakeDBRuntime is an alias for GetDBRuntime.
MakeDBRuntime 是 GetDBRuntime 的别名。
func MakeDistributedLock ¶
func MakeDistributedLock(c runtimecontract.Container) (datacontract.DistributedLock, error)
MakeDistributedLock is an alias for GetDistributedLock.
MakeDistributedLock 是 GetDistributedLock 的别名。
func MakeGRPCConnFactory ¶
func MakeGRPCConnFactory(c runtimecontract.Container) (transportcontract.GRPCConnFactory, error)
MakeGRPCConnFactory is an alias for GetGRPCConnFactory.
MakeGRPCConnFactory 是 GetGRPCConnFactory 的别名。
func MakeGRPCServerRegistrar ¶
func MakeGRPCServerRegistrar(c runtimecontract.Container) (transportcontract.GRPCServerRegistrar, error)
MakeGRPCServerRegistrar is an alias for GetGRPCServerRegistrar.
MakeGRPCServerRegistrar 是 GetGRPCServerRegistrar 的别名。
func MakeGormDB ¶
func MakeGormDB(c runtimecontract.Container) (*gormdb.DB, error)
MakeGormDB is an alias for GetGorm.
MakeGormDB 是 GetGorm 的别名。
func MakeHTTP ¶
func MakeHTTP(c runtimecontract.Container) (transportcontract.HTTP, error)
MakeHTTP is an alias for GetHTTP.
MakeHTTP 是 GetHTTP 的别名。
func MakeHost ¶
func MakeHost(c runtimecontract.Container) (runtimecontract.Host, error)
MakeHost is an alias for GetHost.
MakeHost 是 GetHost 的别名。
func MakeLogger ¶
func MakeLogger(c runtimecontract.Container) (observabilitycontract.Logger, error)
MakeLogger is an alias for GetLogger.
MakeLogger 是 GetLogger 的别名。
func MakeMessagePublisher ¶
func MakeMessagePublisher(c runtimecontract.Container) (integrationcontract.MessagePublisher, error)
MakeMessagePublisher is an alias for GetMessagePublisher.
MakeMessagePublisher 是 GetMessagePublisher 的别名。
func MakeMessageSubscriber ¶
func MakeMessageSubscriber(c runtimecontract.Container) (integrationcontract.MessageSubscriber, error)
MakeMessageSubscriber is an alias for GetMessageSubscriber.
MakeMessageSubscriber 是 GetMessageSubscriber 的别名。
func MakeNamedWith ¶
func MakeNamedWith[T any](c runtimecontract.Container, name, key string) (T, error)
MakeNamedWith resolves a named service and casts it to type T. Returns an error if the service is not bound, resolution fails, or the type does not match.
MakeNamedWith 解析命名服务并转换为类型 T。 如果服务未绑定、解析失败或类型不匹配,返回错误。
func MakeRedis ¶
func MakeRedis(c runtimecontract.Container) (datacontract.Redis, error)
MakeRedis is an alias for GetRedis.
MakeRedis 是 GetRedis 的别名。
func MakeRetry ¶
func MakeRetry(c runtimecontract.Container) (resiliencecontract.Retry, error)
MakeRetry is an alias for GetRetry.
MakeRetry 是 GetRetry 的别名。
func MakeRouter ¶
func MakeRouter(c runtimecontract.Container) (transportcontract.Router, error)
MakeRouter is an alias for GetRouter.
MakeRouter 是 GetRouter 的别名。
func MakeSQLX ¶
func MakeSQLX(c runtimecontract.Container) (*sqlx.DB, error)
MakeSQLX is an alias for GetSQLX.
MakeSQLX 是 GetSQLX 的别名。
func MakeValidator ¶
func MakeValidator(c runtimecontract.Container) (datacontract.Validator, error)
MakeValidator is an alias for GetValidator.
MakeValidator 是 GetValidator 的别名。
func MakeWith ¶
func MakeWith[T any](c runtimecontract.Container, key string) (T, error)
MakeWith resolves a service by key and casts it to the requested type T. Returns an error if the service is not bound, resolution fails, or the type does not match. Prefer this over raw Make + type assertion for type safety.
MakeWith 按 key 解析服务并转换为类型 T。 如果服务未绑定、解析失败或类型不匹配,返回错误。 优先使用此函数而非裸 Make + 类型断言,以获得类型安全。
func MustMakeAppService ¶
func MustMakeAppService[T any](c runtimecontract.Container, key string) T
MustMakeAppService resolves an app service by key and panics on failure. Uses comma-ok type assertion for a descriptive panic message on mismatch.
MustMakeAppService 按 key 解析 app service,失败时 panic。 使用 comma-ok 类型断言,在类型不匹配时给出描述性 panic 信息。
func MustMakeCache ¶
func MustMakeCache(c runtimecontract.Container) datacontract.Cache
MustMakeCache is an alias for GetCacheOrPanic.
MustMakeCache 是 GetCacheOrPanic 的别名。
func MustMakeConfig ¶
func MustMakeConfig(c runtimecontract.Container) datacontract.Config
MustMakeConfig is an alias for GetConfigOrPanic.
MustMakeConfig 是 GetConfigOrPanic 的别名。
func MustMakeCron ¶
func MustMakeCron(c runtimecontract.Container) runtimecontract.Cron
MustMakeCron is an alias for GetCronOrPanic.
MustMakeCron 是 GetCronOrPanic 的别名。
func MustMakeDistributedLock ¶
func MustMakeDistributedLock(c runtimecontract.Container) datacontract.DistributedLock
MustMakeDistributedLock is an alias for GetDistributedLockOrPanic.
MustMakeDistributedLock 是 GetDistributedLockOrPanic 的别名。
func MustMakeGRPCConnFactory ¶
func MustMakeGRPCConnFactory(c runtimecontract.Container) transportcontract.GRPCConnFactory
MustMakeGRPCConnFactory is an alias for GetGRPCConnFactoryOrPanic.
MustMakeGRPCConnFactory 是 GetGRPCConnFactoryOrPanic 的别名。
func MustMakeGRPCServerRegistrar ¶
func MustMakeGRPCServerRegistrar(c runtimecontract.Container) transportcontract.GRPCServerRegistrar
MustMakeGRPCServerRegistrar is an alias for GetGRPCServerRegistrarOrPanic.
MustMakeGRPCServerRegistrar 是 GetGRPCServerRegistrarOrPanic 的别名。
func MustMakeGorm ¶
func MustMakeGorm(c runtimecontract.Container) *gormdb.DB
MustMakeGorm is an alias for GetGormOrPanic.
MustMakeGorm 是 GetGormOrPanic 的别名。
func MustMakeGormDB ¶
func MustMakeGormDB(c runtimecontract.Container) *gormdb.DB
MustMakeGormDB is an alias for GetGormOrPanic.
MustMakeGormDB 是 GetGormOrPanic 的别名。
func MustMakeHTTP ¶
func MustMakeHTTP(c runtimecontract.Container) transportcontract.HTTP
MustMakeHTTP is an alias for GetHTTPOrPanic.
MustMakeHTTP 是 GetHTTPOrPanic 的别名。
func MustMakeJWT ¶
func MustMakeJWT(c runtimecontract.Container) securitycontract.JWTService
MustMakeJWT is an alias for GetJWTOrPanic.
MustMakeJWT 是 GetJWTOrPanic 的别名。
func MustMakeJWTService ¶
func MustMakeJWTService(c runtimecontract.Container) securitycontract.JWTService
MustMakeJWTService resolves the JWT service and panics on failure.
MustMakeJWTService 解析 JWT 服务,失败时 panic。
func MustMakeLogger ¶
func MustMakeLogger(c runtimecontract.Container) observabilitycontract.Logger
MustMakeLogger is an alias for GetLoggerOrPanic.
MustMakeLogger 是 GetLoggerOrPanic 的别名。
func MustMakeMessagePublisher ¶
func MustMakeMessagePublisher(c runtimecontract.Container) integrationcontract.MessagePublisher
MustMakeMessagePublisher is an alias for GetMessagePublisherOrPanic.
MustMakeMessagePublisher 是 GetMessagePublisherOrPanic 的别名。
func MustMakeMessageSubscriber ¶
func MustMakeMessageSubscriber(c runtimecontract.Container) integrationcontract.MessageSubscriber
MustMakeMessageSubscriber is an alias for GetMessageSubscriberOrPanic.
MustMakeMessageSubscriber 是 GetMessageSubscriberOrPanic 的别名。
func MustMakeNamedWith ¶
func MustMakeNamedWith[T any](c runtimecontract.Container, name, key string) T
MustMakeNamedWith resolves a named service and casts it to type T, panicking on failure.
MustMakeNamedWith 解析命名服务并转换为类型 T,失败时 panic。
func MustMakeRetry ¶
func MustMakeRetry(c runtimecontract.Container) resiliencecontract.Retry
MustMakeRetry is an alias for GetRetryOrPanic.
MustMakeRetry 是 GetRetryOrPanic 的别名。
func MustMakeRouter ¶
func MustMakeRouter(c runtimecontract.Container) transportcontract.Router
MustMakeRouter is an alias for GetRouterOrPanic.
MustMakeRouter 是 GetRouterOrPanic 的别名。
func MustMakeSQLX ¶
func MustMakeSQLX(c runtimecontract.Container) *sqlx.DB
MustMakeSQLX is an alias for GetSQLXOrPanic.
MustMakeSQLX 是 GetSQLXOrPanic 的别名。
func MustMakeValidator ¶
func MustMakeValidator(c runtimecontract.Container) datacontract.Validator
MustMakeValidator is an alias for GetValidatorOrPanic.
MustMakeValidator 是 GetValidatorOrPanic 的别名。
func MustMakeWith ¶
func MustMakeWith[T any](c runtimecontract.Container, key string) T
MustMakeWith resolves a service by key and casts it to type T, panicking on failure. Prefer this over raw MustMake + type assertion for type safety.
MustMakeWith 按 key 解析服务并转换为类型 T,失败时 panic。 优先使用此函数而非裸 MustMake + 类型断言,以获得类型安全。
func PingDBRuntime ¶
PingDBRuntime performs a best-effort health check against different DB runtime shapes.
PingDBRuntime 针对不同数据库运行时形态执行尽力而为的健康检查。
func Resolve ¶ added in v0.1.4
func Resolve(ctx context.Context) runtimecontract.Container
Resolve 从 ctx 中提取 Container,提取不到则使用全局默认 Container。 优先级:ctx 中的 Container > 全局默认 Container > noopContainer。 传入 context.Background() 也能工作(fallback 到全局默认)。
Resolve extracts Container from ctx; falls back to the global default. Priority: ctx Container > global default > noopContainer. context.Background() works by falling back to the global default.
func SetDefault ¶ added in v0.1.4
func SetDefault(c runtimecontract.Container)
SetDefault 设置全局默认 Container。 仅在 bootstrap 阶段调用一次,启动前所有 facade 调用将返回 ErrDefaultContainerNotSet。
SetDefault replaces the process-wide default container.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is the default runtime container implementation used by the framework.
Container 是框架使用的默认运行时容器实现。
func New ¶
func New() *Container
New creates a new runtime container and self-binds the container contract.
New 创建一个新的运行时容器,并将容器契约自身注册进去。
func (*Container) Bind ¶
func (c *Container) Bind(key string, factory runtimecontract.Factory, singleton bool)
Bind registers a factory under the given key. If the key is already bound, a warning is logged and the previous binding is replaced.
Bind 将指定 factory 注册到目标 key 之下。 如果 key 已绑定,打印警告日志并替换原有绑定。
func (*Container) DebugPrint ¶
DebugPrint returns a human-readable snapshot of the container state.
DebugPrint 返回容器状态的人类可读快照。
func (*Container) Destroy ¶
Destroy calls all registered closers in reverse order and marks the container as destroyed. After Destroy, Make/MakeNamed return ErrContainerDestroyed.
Destroy 按注册逆序调用所有 Closer,并将容器标记为已销毁。 销毁后 Make/MakeNamed 返回 ErrContainerDestroyed。
func (*Container) IsBind ¶
IsBind reports whether the key is directly bound or promised by a deferred provider. 使用单次 RLock 避免 TOCTOU 竞态。
IsBind 返回目标 key 是否已直接绑定,或是否由延迟 provider 承诺提供。
func (*Container) IsBindNamed ¶
IsBindNamed reports whether a named binding exists.
IsBindNamed 返回指定命名绑定是否存在。
func (*Container) Make ¶
Make resolves a service by key. Returns ErrContainerDestroyed if the container has been destroyed. Returns CircularDependencyError if a circular dependency is detected.
Make 按 key 解析服务实例。 如果容器已销毁,返回 ErrContainerDestroyed。 如果检测到循环依赖,返回 CircularDependencyError。
func (*Container) MakeNamed ¶
MakeNamed resolves a named service by name and key. Returns ErrContainerDestroyed if the container has been destroyed. Returns CircularDependencyError if a circular dependency is detected.
MakeNamed 按名称和 key 解析命名服务实例。 如果容器已销毁,返回 ErrContainerDestroyed。 如果检测到循环依赖,返回 CircularDependencyError。
func (*Container) MustMake ¶
MustMake resolves a service by key and panics on failure. The panic message includes the key name for easier debugging.
MustMake 按 key 解析服务,失败时直接 panic。 panic 信息包含 key 名称以便调试。
func (*Container) MustMakeNamed ¶
MustMakeNamed resolves a named service by name and key and panics on failure. The panic message includes the name and key for easier debugging.
MustMakeNamed 按名称和 key 解析命名服务,失败时直接 panic。 panic 信息包含 name 和 key 以便调试。
func (*Container) NamedBind ¶
func (c *Container) NamedBind(name, key string, factory runtimecontract.Factory, singleton bool)
NamedBind registers a named factory under the given key. Allows multiple implementations of the same key to coexist under different names. If the name+key combination is already bound, a warning is logged and the previous binding is replaced.
NamedBind 将命名 factory 绑定到目标 key 之下。 允许同一 key 的多个实现以不同名称共存。 如果 name+key 组合已绑定,打印警告日志并替换原有绑定。
func (*Container) ProviderDAG ¶
func (c *Container) ProviderDAG() runtimecontract.ProviderDAG
ProviderDAG builds and returns the provider dependency graph. It analyzes all registered providers, their provides/depends declarations, and computes the recommended load order with cycle detection.
ProviderDAG 构建并返回 provider 依赖图。 分析所有已注册的 provider,其 provides/depends 声明, 计算推荐加载顺序并检测循环依赖。
func (*Container) ProviderNames ¶
ProviderNames returns the registered provider names in lexicographical order.
ProviderNames 按字典序返回当前已注册的 provider 名称列表。
中文说明: - 这是一个仅供调试与框架命令使用的辅助方法。 - 它没有被放入公共 `contract.Container` 接口,避免把管理侧能力暴露成运行时通用契约。 - 当前主要服务于类似 `gorp provider list` 这类工具场景。
func (*Container) RegisterCloser ¶
RegisterCloser registers an io.Closer to be called during Destroy. Closers are called in reverse registration order.
RegisterCloser 注册一个 io.Closer,在 Destroy 时调用。 Closer 按注册逆序调用。
func (*Container) RegisterProvider ¶
func (c *Container) RegisterProvider(p runtimecontract.ServiceProvider) error
RegisterProvider registers a provider into the container and loads it immediately when not deferred.
RegisterProvider 将 provider 注册进容器;若不是延迟 provider,则立刻装载。
func (*Container) RegisterProviders ¶
func (c *Container) RegisterProviders(providers ...runtimecontract.ServiceProvider) error
RegisterProviders registers multiple providers in order.
RegisterProviders 按顺序注册多个 provider。
func (*Container) RegisteredProviders ¶
func (c *Container) RegisteredProviders() []runtimecontract.ProviderInfo
RegisteredProviders returns information about all registered providers.
RegisteredProviders 返回所有已注册 provider 的信息。