Help us shape the future of Go! Take the 2026 Go Developer Survey

runtime

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package runtime provides ORM backend abstraction and unified runtime services. This provider binds multiple contracts based on the configured backend:

ORM 运行时包,提供 ORM 后端抽象和统一的运行时服务。 此 Provider 根据配置的后端绑定多个契约:

  • ORMBackendKey: The backend name (gorm/sqlx/ent)
  • DBRuntimeKey: The actual DB client (GORM/SQLX/Ent)
  • MigratorKey: The migrator (GORM, except Ent)
  • SQLExecutorKey: The SQL executor (SQLX)

Configuration via config.yaml:

通过 config.yaml 配置:

database:
  backend: gorm  # or sqlx, ent

Eg:

// 注册 Provider
app.Register(runtime.NewProvider())

// 获取统一运行时服务
backend := c.MustMake(datacontract.ORMBackendKey).(string)
dbRuntime := c.MustMake(datacontract.DBRuntimeKey)

Index

Constants

This section is empty.

Variables

View Source
var ErrMigratorUnsupported = errors.New(`orm.runtime: migrator is not supported for backend "ent"`)

ErrMigratorUnsupported 表示当前后端(ent)不提供迁移器。 用哨兵错误而非 os.ErrInvalid,让调用方可用 errors.Is 精确区分根因。

Functions

This section is empty.

Types

type Provider

type Provider struct{}

Provider registers ORM backend abstraction and unified runtime services.

Provider 注册 ORM 后端抽象和统一的运行时服务。

func NewProvider

func NewProvider() *Provider

NewProvider creates a new runtime provider instance.

NewProvider 创建新的运行时 Provider 实例。

func (*Provider) Boot

Boot is a no-op for runtime provider.

Boot 运行时 Provider 无启动逻辑。

func (*Provider) DependsOn

func (p *Provider) DependsOn() []string

DependsOn returns the keys this provider depends on. Runtime provider depends on Config for backend selection.

DependsOn 返回该 provider 依赖的 key。 Runtime provider 依赖 Config 获取后端选择。

func (*Provider) IsDefer

func (p *Provider) IsDefer() bool

IsDefer returns false, runtime should be initialized immediately.

IsDefer 返回 false,运行时服务应立即初始化。

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name "orm.runtime".

Name 返回 Provider 名称 "orm.runtime"。

func (*Provider) Provides

func (p *Provider) Provides() []string

Provides returns the list of contracts this provider provides.

Provides 返回此 Provider 提供的契约列表。

func (*Provider) Register

func (p *Provider) Register(c runtimecontract.Container) error

Register binds multiple factories to the container based on backend config. Core logic: Determine backend from config, then bind appropriate implementations.

Register 根据后端配置将多个工厂绑定到容器。 核心逻辑:从配置确定后端,然后绑定相应的实现。

Jump to

Keyboard shortcuts

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