scene

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 9 Imported by: 0

README

稀音微服务框架

名字来源: 稀音 Arknights

Author: @Aynakeya(Yiyang Lu)

Still In development.

For design details and development diaries, please refer to my blog

For example usage, please refer to scene-template

Framework structure

structure

TODO

  • interface logger proxy generation

Driver

  • Simple Database Driver
Repository
  • Code Generator

Documentation

Index

Constants

View Source
const (
	EnvDevelopment = "development"
	EnvProduction  = "production"
	EnvTest        = "test"
)
View Source
const (
	ImplTypeScene  = ImplType("scene")  // scenario type
	ImplTypeModule = ImplType("module") // module type
)
View Source
const Version = "0.4.0"

Variables

View Source
var (
	AppName         string = ""
	AppBuildTime    string = "0"
	AppBuildHash    string = "0000000000000000000000000000000000000000"
	AppBuildVersion string = "v0.0.0"
)
View Source
var Environment = EnvDevelopment

Functions

func Applications added in v0.4.0

func Applications[T Application](applications []Application) []T

Applications returns the applications that implement T.

func ContextFindValue

func ContextFindValue[T any](ctx context.Context, key any) (T, bool)

func ContextSetValue

func ContextSetValue[T any](ctx context.Context, key any, value T) context.Context

func NewContext

func NewContext() context.Context

Types

type AppInit

type AppInit[T Application] func() T

AppInit constructs an application.

type Application

type Application interface {
	Name() ImplName // return scene
}

type Based added in v0.3.7

type Based[T any] interface {
	Base() T
}

Based is an interface imply this service might have an internal core implementation

type Defaultable added in v0.2.10

type Defaultable[T any] interface {
	Default() T
}

type Engine

type Engine interface {
	Run() error
	Start() error
	Stop()

	ListContainers() []Scene
	GetContainer(name string) Scene
}

type IDefaultableModuleFactory

type IDefaultableModuleFactory[T any] interface {
	IModuleFactory
	Defaultable[T]
}

type IModuleDependencyProvider

type IModuleDependencyProvider[T any] interface {
	Provide() T
}

type IModuleFactory

type IModuleFactory interface {
	Init(container *registry.Container)
	Apps() []Application
}

IModuleFactory declares the objects and applications owned by one module.

type ImplName

type ImplName struct {
	ImplType       ImplType
	Module         string
	Interface      string
	Implementation string
}

func NewImplName

func NewImplName(implType ImplType, module, implementation, version string) ImplName

func NewImplNameNoVer

func NewImplNameNoVer(implType ImplType, module, iface string) ImplName

func NewModuleImplName added in v0.2.6

func NewModuleImplName(module, iface, implementation string) ImplName

func NewModuleImplNameNoVer added in v0.2.6

func NewModuleImplNameNoVer(module, iface string) ImplName

func NewSceneImplName

func NewSceneImplName(module, iface, version string) ImplName

func NewSceneImplNameNoVer

func NewSceneImplNameNoVer(module, iface string) ImplName

func (ImplName) EndpointName

func (i ImplName) EndpointName() string

currently no usage?

func (ImplName) ExportName added in v0.2.8

func (i ImplName) ExportName() string

ExportName return interface name with capitalized module name used by arpc

func (ImplName) Identifier

func (i ImplName) Identifier() string

Identifier returns a string identifier of the implementation name.

func (ImplName) MethodName added in v0.3.2

func (i ImplName) MethodName(method ...string) string

MethodName return method name in the for this interface used by mcp tools

func (ImplName) String

func (i ImplName) String() string

String returns a string representation of the implementation name. String is a pretty representation of the implementation name. If you want to use the implementation name as an identifier, use Identifier().

type ImplType

type ImplType string

type Lifecycle added in v0.4.0

type Lifecycle interface {
	Setup() error
	TearDown() error
}

Lifecycle is initialized when its module is loaded and released when the module is unloaded.

type ModuleFactory

type ModuleFactory struct{}

func (ModuleFactory) Apps

func (ModuleFactory) Apps() []Application

func (ModuleFactory) Init

type ModuleFactoryArray

type ModuleFactoryArray []IModuleFactory

type ModuleLoader added in v0.4.0

type ModuleLoader struct {
	// contains filtered or unexported fields
}

ModuleLoader builds a flat list of module factories in one registry Scope.

func NewModuleLoader added in v0.4.0

func NewModuleLoader(factories ModuleFactoryArray) *ModuleLoader

func NewModuleLoaderIn added in v0.4.0

func NewModuleLoaderIn(scope *registry.Scope, factories ModuleFactoryArray) *ModuleLoader

NewModuleLoaderIn creates a module loader backed by scope.

func (*ModuleLoader) Applications added in v0.4.0

func (l *ModuleLoader) Applications() []Application

Applications returns the applications declared during Init in module order.

func (*ModuleLoader) Containers added in v0.4.0

func (l *ModuleLoader) Containers() []*registry.Container

Containers returns the initialized module containers in factory order.

func (*ModuleLoader) Init added in v0.4.0

func (l *ModuleLoader) Init() error

Init declares all modules, resolves their dependencies, and performs injection. It does not run lifecycle Setup.

func (*ModuleLoader) Scope added in v0.4.0

func (l *ModuleLoader) Scope() *registry.Scope

Scope returns the registry Scope owned by this loader.

func (*ModuleLoader) Setup added in v0.4.0

func (l *ModuleLoader) Setup() error

Setup initializes module lifecycles in dependency order. Init must complete successfully before Setup is called.

func (*ModuleLoader) TearDown added in v0.4.0

func (l *ModuleLoader) TearDown() error

TearDown releases initialized modules in reverse dependency order.

type ModuleName added in v0.2.6

type ModuleName string

func (ModuleName) ImplName added in v0.2.6

func (l ModuleName) ImplName(iface, implementation string) ImplName

func (ModuleName) ImplNameNoVer added in v0.2.6

func (l ModuleName) ImplNameNoVer(implementation string) ImplName

func (ModuleName) String added in v0.2.6

func (l ModuleName) String() string

func (ModuleName) TableName added in v0.2.6

func (l ModuleName) TableName(table string) string

type MutableContext added in v0.3.6

type MutableContext interface {
	SetContextValue(key any, value any)
}

type Named added in v0.2.8

type Named interface {
	ImplName() ImplName
}

type Scene added in v0.3.0

type Scene interface {
	Named

	Start() error                   // start container
	Stop(ctx context.Context) error // stop container

	ListAppNames() []string // return application names
}

Scene is the delivery (controller) layer container, contains application from each module

type SceneDefinition added in v0.4.0

type SceneDefinition struct {
	// contains filtered or unexported fields
}

SceneDefinition is the type-erased scene declaration consumed by an Engine. Use WithScene to create one from a typed SceneFactory.

func WithScene added in v0.4.0

func WithScene[T Application](factory SceneFactory[T]) SceneDefinition

WithScene declares a Scene. The factory receives only applications that implement T, preserving their module declaration order.

func (SceneDefinition) Build added in v0.4.0

func (d SceneDefinition) Build(loader *ModuleLoader) (Scene, error)

Build builds the declared Scene from an initialized ModuleLoader.

type SceneFactory added in v0.4.0

type SceneFactory[T Application] interface {
	Build(scope *registry.Scope, applications []T) (Scene, error)
}

SceneFactory builds one Scene from applications of the matching type.

Directories

Path Synopsis
cmd
scene command
composition
orm
Package orm integrates GORM with Scene's data-source, logging, setup, and dependency-injection lifecycle.
Package orm integrates GORM with Scene's data-source, logging, setup, and dependency-injection lifecycle.
infrastructure
lens
spa
pkg
Package registry implements module-scoped dependency declaration and injection.
Package registry implements module-scoped dependency declaration and injection.
scenes
cmd
gin
Package gin integrates Gin HTTP routing with Scene applications, dependency injection, request binding, middleware, and the common response envelope.
Package gin integrates Gin HTTP routing with Scene applications, dependency injection, request binding, middleware, and the common response envelope.
mcp

Jump to

Keyboard shortcuts

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